필터 지우기
필터 지우기

How can I plot 2 vectors of different length?

조회 수: 48 (최근 30일)
Jonathan Bijman
Jonathan Bijman 2019년 6월 12일
댓글: Michael Mauersberger 2020년 4월 29일
Hello everyone
It could be the question sounds stupid, but I have 32 data (which correspond to averages of 9 measurements) and I want to plot along aprox 50 days
(Because there weren´t measurements some days)
Anyone has an idea of how can I do that? I was thinking by scatter, but appears the same error (different lenghts)
Thank u

채택된 답변

Star Strider
Star Strider 2019년 6월 12일
Without knowing any constraints you may have, try this:
data = rand(1, 32); % Create Data Vector
x = linspace(0, 50, numel(data)); % Create Independent Variable Vector
figure
plot(x, data)
If your data were calculated with respect to specific days, use a vector of those days as ‘x’. So long as there are exactly 32 of them, you can easily plot them.
  댓글 수: 5
Star Strider
Star Strider 2019년 6월 12일
Our pleasures!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 6월 12일
You know which days had valid measurements. Pass the time coordinate corresponding to those days as the "x" coordinate to plot, if you want a line plot that draws between the missing data.
stem() plot might make sense in some cases.
It is possible to draw in segments. For that purpose, pass in nan as the y coordinates for the missing measurements, and be sure to include a marker type. You want the marker because you might have patterns such as NaN Point NaN and plot() will only draw a line when there are at least two finite points in a row.
  댓글 수: 1
Jonathan Bijman
Jonathan Bijman 2019년 6월 12일
For "y" variable I have this:
Clean=table2cell(datatable);
nrow = height(datatable);
lastidx = floor(nrow/9) * 9;
Voc_p = mean(reshape(datatable{1:lastidx,7}, 9, []));
Voc_promedio=Voc_p.';
it results 32 data
For "x" variable I create a table with all the dates and load the mat file:
load('fechas.mat');
c=table2array(fechas);
When I try to plot with stem:
x=c
y=Voc_promedio
stem(x,y)
Appears this error:
Error using stem (line 43)
X must be same length as Y.
Error in Prueba_1 (line 34)
stem(x,y)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by