Why am I getting this error about vectors being the same length? Error in ==> plot_excel at 15 plot(X, F1);

1 view (last 30 days)
folder='S:\TVC\MC10\Wedging\PN8604rA1\RTR FX01046 101118'; %folder location, change this to run elsewhere
filetype = '*.xlsm'; %macro excelbooks
f=fullfile(folder, filetype);
d=dir(f);
for k=1:numel(d);
filename = d(k).name; %set filename for excel data
X = xlsread(filename,'Sheet2', 'A2:A27'); %selects x-range
F1 = xlsread(filename,'Sheet2', 'F2:F27'); %sensor 0 values
F2 = xlsread(filename,'Sheet2', 'G2:G27'); %snesor 1 values
F3 = xlsread(filename,'Sheet2', 'H2:H27'); %sensor 2 values
Force = xlsread(filename,'Sheet2', 'J2:J27'); %derived force value
plot(X, F1);
xlabel('re-advancment');
ylabel('Force Units');
hold on;
plot(X, F2, 'r');
plot(X, F3,'g');
plot(X, Force, 'm');
legend('S1','S2','S3','Derived');
title(filename);
hold off;
clc;
end
  3 Comments
Katie Ziegler
Katie Ziegler on 16 Oct 2018
F1 and X are the same sixe, everything is 25x1. For some reason X is 26x1 in the second loop through and I can't figure out why.

Sign in to comment.

Answers (2)

KSSV
KSSV on 16 Oct 2018
Edited: KSSV on 16 Oct 2018
To plot, you need to have x and y of same length. You cannot plot them, when they are of different sizes.
x = 1:10 ;
plot(x,rand(10,1)) ;
title('works becuase x and y are of same length')
fprintf('error becuas x and y are of different size\n')
plot(x,rand(1,9))
In your case X and F1 are of differnt sizes..how you expect them to plot?

madhan ravi
madhan ravi on 16 Oct 2018
folder='S:\TVC\MC10\Wedging\PN8604rA1\RTR FX01046 101118'; %folder location, change this to run elsewhere
filetype = '*.xlsm'; %macro excelbooks
f=fullfile(folder, filetype);
d=dir(f);
for k=1:numel(d);
filename = d(k).name; %set filename for excel data
X = xlsread(filename,'Sheet2', 'A2:A27'); %selects x-range
F1 = xlsread(filename,'Sheet2', 'F2:F27'); %sensor 0 values
F2 = xlsread(filename,'Sheet2', 'G2:G27'); %snesor 1 values
F3 = xlsread(filename,'Sheet2', 'H2:H27'); %sensor 2 values
Force = xlsread(filename,'Sheet2', 'J2:J27'); %derived force value
plot(X(1:numel(F1)), F1);
xlabel('re-advancment');
ylabel('Force Units');
hold on;
plot(X(1:numel(F2)), F2, 'r');
plot(X(1:numel(F3)), F3,'g');
plot(X(1:numel(Force)), Force, 'm');
legend('S1','S2','S3','Derived');
title(filename);
hold off;
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!