Matlab Error Using Plot Vectors Must Be The Same Lengths
Contents |
Support Answers MathWorks Search MathWorks.com MathWorks Answers Support MATLAB Answers™ MATLAB Central Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Ask Answer Browse how to make vectors the same length matlab More Contributors Recent Activity Flagged Content Flagged as Spam Help MATLAB Central
How To Plot Vectors Of Different Length In Matlab
Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Ask Answer Browse More Contributors Recent how to use linspace in matlab Activity Flagged Content Flagged as Spam Help Trial software alexr (view profile) 1 question 0 answers 0 accepted answers Reputation: 0 Vote0 Vectors must be the same lengths; plotting Asked by
Error Using Plot Not Enough Input Arguments
alexr alexr (view profile) 1 question 0 answers 0 accepted answers Reputation: 0 on 2 May 2011 2,322 views (last 30 days) 2,322 views (last 30 days) I have googled this to death, the common error was people looping arrays. I just have 2 simple sets and cant see where the error is.simulated=[0.0000000 4.3830000 4.9470000 2.0180000 0.1761000 0.0162800 4.3650000 4.9540000 2.0170000 0.1760000 0.0162700 ] plot function in matlab actual= [0.0750000 4.0750000 4.7630000 3.5130000 0.5125000 0.1375000 2.6380000 4.5750000 4.8880000 1.5130000 0.3250000 ] x = 0:0.0002:0.01; plot(x, simulated, x, actual); legend('Simulated', 'Actual') ylabel('Current (mA)') xlabel('Time ( mS )') title('Current across R2 as a function of VS','FontSize',12) 3 Comments Show all comments Paulo Silva Paulo Silva (view profile) 14 questions 952 answers 365 accepted answers Reputation: 2,344 on 3 May 2011 Direct link to this comment: https://www.mathworks.com/matlabcentral/answers/6670#comment_13754 For the plot function to work x and y must have the same number of elements,your x vector got 51 elements and the simulated and actual vectors just 11. You can solve the problem by making the x vector with 11 elements instead of the 51 or by adding NaN values to the simulated vector like this simulated(end:end+numel(x)-numel(simulated))=nan; plot(x,simulated) (I couldn't post an answer to this question for some unknown reason, it gives me always one error) Andrew Newell Andrew Newell (view profile) 15 questions 717 answers 273 accepted answers Reputation: 1,832 on 3 May 2011 Direct link to this comment: https://www.mathworks.com/matlabcentral/answers/6670#comment_13756 To create an array x with the same span of values but the right size, you could do this: x = linspace(0,0
Support Answers MathWorks Search MathWorks.com MathWorks Answers Support MATLAB Answers™ MATLAB Central Community Home
How To Plot In Matlab
MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak
Matlab Subplot
Anniversary Home Ask Answer Browse More Contributors Recent Activity Flagged Content Flagged as Spam Help MATLAB Central Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Ask Answer Browse More Contributors Recent Activity Flagged https://www.mathworks.com/matlabcentral/answers/6670-vectors-must-be-the-same-lengths-plotting Content Flagged as Spam Help Trial software Priya (view profile) 42 questions 0 answers 0 accepted answers Reputation: 3 Vote0 error using plot:Vectors must be the same lengths Asked by Priya Priya (view profile) 42 questions 0 answers 0 accepted answers Reputation: 3 on 19 Aug 2014 Latest activity https://www.mathworks.com/matlabcentral/answers/151567-error-using-plot-vectors-must-be-the-same-lengths Commented on by Priya Priya (view profile) 42 questions 0 answers 0 accepted answers Reputation: 3 on 20 Aug 2014 581 views (last 30 days) 581 views (last 30 days) I get this error in the plot line. V=20; t_sim=0.02; sample_distance=0.2; ts=sample_distance/V; step_time=1; step_size=0.01; collect_ts=ts*1; t_plot=(0:collect_ts:t_sim); figure(6); plot(t_plot,simout(:,1));hold all;plot(x,y);grid on; xlabel('Time (s)');ylabel('lateral position (m)'); >> size(t_plot)ans = 1 3 >> size(simout)ans = 21 71Can anyone please tell the reason for this error and how to solve it. 4 Comments Show 1 older comment Adam Adam (view profile) 10 questions 1,019 answers 446 accepted answers Reputation: 2,291 on 19 Aug 2014 Direct link to this comment: https://www.mathworks.com/matlabcentral/answers/151567#comment_232490 It's impossible to say really how to solve it. The plot doesn't work because the things you are plotting are clearly not the same size, but your posted code gives no indication of what simout is.I suspect your parameter
Support Answers MathWorks Search MathWorks.com MathWorks Answers Support MATLAB Answers™ MATLAB Central Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Ask Answer Browse More Contributors Recent Activity Flagged Content Flagged as Spam Help MATLAB Central https://www.mathworks.com/matlabcentral/answers/129643-error-using-plot-vectors-must-be-the-same-lengths Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Ask Answer Browse More Contributors Recent Activity Flagged Content Flagged as Spam Help Trial software Mini Me (view profile) 25 questions 11 answers 0 accepted answers Reputation: 0 Vote0 Error using ==> plot Vectors must be the same lengths. Asked by Mini Me Mini Me (view profile) 25 questions 11 answers 0 accepted answers Reputation: 0 on 14 May 2014 Latest how to activity Edited by Mini Me Mini Me (view profile) 25 questions 11 answers 0 accepted answers Reputation: 0 on 15 May 2014 194 views (last 30 days) 194 views (last 30 days) What if you have two vectors. let's say A size is 1200 x 1 and B size is 4 x 1... B is timestamp of each file processed in a directory.. meaning each file has 300 samples in it i.e 1200/4 gives you only error using plot 4 diff timestamps. what if i want plot(B,A) for that the timestamp would display every 300 samples on the x axis. of course when i tried to do it with my code i get this error: Error using ==> plot Vectors must be the same lengths. filedir = dir(dirpath) timerArray=[]; Array=[]; for cnt=1:length(filedir) timerArray=vertcat(timerArray, (filedir(cnt).datenum)); data=fread(fid,[rows,cols],'double') Array=horzcat(Array, data); plot(timerArray,Ex) datetick('x' , 13 , 'keeplimits') endpart of the code if there are errors it might because i was cropping the most relevant part of the code for the question. 0 Comments Show all comments Tags vectorsplot Products MATLAB Related Content 1 Answer Walter Roberson (view profile) 27 questions 27,753 answers 9,695 accepted answers Reputation: 50,169 Vote0 Link Direct link to this answer: https://www.mathworks.com/matlabcentral/answers/129643#answer_136819 Answer by Walter Roberson Walter Roberson (view profile) 27 questions 27,753 answers 9,695 accepted answers Reputation: 50,169 on 14 May 2014 How many output lines are expected? 1 or 4 or 300?Is A(2) to be considered to be at a different time than A(1)? If so then are the times for A(1:301) to be equally distributed over the time range between B(1) and B(2)? And A(301:601) times to b equally distributed over the time range B(2) to B(3) ? If so then what is the final time for A(1200) as there is no B(5) to know the interpolation?Or is there a fixe