0

I am importing data from three files and parsing it to obtain time and voltage values from each file. These values need to be plotted against each other on the same plot.

The data is held in a total of six matrices, one for time and one for voltage for each of the three data sets.

Matrix dimensions: matlab data sets: 1000x1, ltspice: 465x1, oscope: 2500x1.

Matlab finds an error in the use of the plot function:

plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');

Is this an issue because the matrix dimension vary between independent and dependent sets?

Full code for script:

clear;
clc;

%% Import
%Read in files

matlab_t=dlmread('ENGR_222_Project_1_data.csv',',',[16 0 1015 0]);
matlab_v=dlmread('ENGR_222_Project_1_data.csv',',',[16 1 1015 1]); 

ltspice_t=xlsread('ltspicedata_excel.xlsx','A1:A465');
ltspice_v=xlsread('ltspicedata_excel.xlsx','B1:B465');

oscope_t=xlsread('oscope_data.xlsx','D1:D2500');
oscope_v=xlsread('oscope_data.xlsx','E1:E2500');

%% Plot

plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');
5
  • Yes. You need both the X and Y axis to be of the same dimensions to plot the graph. Make both the dimensions same and you should be able to plot the graph Commented Apr 22, 2016 at 3:45
  • @AswinPJ How would I do that? The time domain is incremented differently for each time matrix. Commented Apr 22, 2016 at 3:48
  • Can you update the question with the dimensions of matlab_t, matlab_v, ltspice_t,ltspice_v and oscope_t,oscope_v? Commented Apr 22, 2016 at 4:05
  • 1
    This is most probably because you have different dimensions for your time and voltage matrices. The dimensions of matlab_t and matlab_v should be the same. So should be that of ltspice_v and ltspice_t. And oscope_t,oscope_v. Commented Apr 22, 2016 at 4:10
  • @AswinPJ You are correct. I have answered my own question using your comment. Commented Apr 22, 2016 at 23:48

1 Answer 1

1

To plot multiple matrices on the same plot, each matrix must have the same dimensions. In the case where we have two 465 X 1 matrices, two 1000 X 1 matrices, and two 2500 X 1 matrices, all matrices must have the dimension 2500 X 1.

To increase the dimensions of the of the smaller matrices, redefine the matrix to that size and set the empty cells equal to zero.

This is accomplished in the following code:

matlab_t(2500,1)=0;
matlab_v(2500,1)=0;
ltspice_t(2500,1)=0;
ltspice_v(2500,1)=0;

Complete code using fix:

clear;
clc;

%% Import
%Read in files

matlab_t=dlmread('ENGR_222_Project_1_data.csv',',',[16 0 1015 0]);
matlab_v=dlmread('ENGR_222_Project_1_data.csv',',',[16 1 1015 1]); 

ltspice_t=xlsread('ltspicedata_excel.xlsx','A1:A465');
ltspice_v=xlsread('ltspicedata_excel.xlsx','B1:B465');

oscope_t=xlsread('oscope_data.xlsx','D1:D2500');
oscope_v=xlsread('oscope_data.xlsx','E1:E2500');

% Redefine matrices to equal size

 matlab_t(2500,1)=0;
 matlab_v(2500,1)=0;
 ltspice_t(2500,1)=0;
 ltspice_v(2500,1)=0;

 %% Plot

plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.