Why I do not get the graphics as I want. It is not a code problem

Hi, so my problem is that I do get the graphics in blank. I post the code and the data I am working with to help you understand the problem. Matlab do not tell me I have a problem with the code. I guess is the amount of information or the amount of graphics at the same time(30) but I do not know, I let you tell me. Here is the code :
k = length(DataRaval);
for k = 1:48:1439
nexttile
plot(datenum(DataRaval(k,1)),TempRaval(k,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura en ºC')
title('Temperatura durant el dia 1 de març')
end
and the data used.
If you know the problem and know the solution too please share!

 채택된 답변

DGM
DGM 2021년 12월 1일
You have to plot more than one data point.
load DataRaval2.mat
load TempRaval2.mat
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura en ºC')
title('Temperatura durant el dia 1 de març')
end

댓글 수: 7

why do you create vend? I do not understand tthe finality because it worked to me but some days I do not have the hole plot look. And how can I change the title to see each graph as one different day?
You're incrementing through TempRavel in steps of 48. 1439 is not integer-divisible by 48. Using min() in calculating the end index avoids errors caused by indexing off the end of the vector.
I guess I should've looked as to which samples were missing. I assumed it was the last one. It was instead the first one. I just added a NaN padding sample to the beginning of the set. That way the plots don't extend into the next day.
load DataRaval2.mat
load TempRaval2.mat
DataRaval = [DataRaval(1); DataRaval];
TempRaval = [NaN; TempRaval];
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura en ºC')
title('Temperatura durant el dia 1 de març')
end
If you have other datasets, you'll have to do whatever you need to do to make sure the loop lines up with days and that the dataset represents an integer number of days.
okay so in the end it ended like this:
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura en ºC')
title('Temperatura durant el dia 1 de març')
end
there are 1440 and 48 is multiple of 1440 so I got it in the end. But one question more how can I change the title for each day?
DGM
DGM 2021년 12월 1일
편집: DGM 2021년 12월 1일
Something like this should work.
title(sprintf('Temperatura durant el dia %d de març',floor(k/48)+1))
yeah It worked. Thank you. One last question if I want to write the average of each day how can I do it. I wrote this line:
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura en ºC')
title(sprintf('Temperatura dia %d de març',floor(k/48)+1))
title(sprintf('La media del dia %d',mean(TempRaval(k:vend,1))))
end
it gives me the average but with cientific notation and I want just the number and the one or two digits after the comma. And I do not want it as a title just as extra information how could I do it?
There's so little room in the plot box that I'd avoid trying to make an annotation out of it. If you use a supertitle, you can move the common information out of the subplot titles. You could then maybe do something like this.
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas')
ylabel('Temperatura (ºC)') % this is a bit shorter
title(sprintf('Març %d: Media %.2fºC', ... % day and avg info
floor(k/48)+1,mean(TempRaval(k:vend,1),'omitnan')))
end
sgtitle('Temperatura dias de març') % overall title
You could also split the title across two lines
title(sprintf('Març %d: \nTemperatura Media %.2fºC', ...
floor(k/48)+1,mean(TempRaval(k:vend,1),'omitnan')))
That would give you more width for text, but it's going to make your plot boxes smaller.
If you really just want to use a text annotation, you could, but you're not going to have much room
for k = 1:48:numel(TempRaval)
nexttile
vend = min(k+48,numel(TempRaval));
plot(datenum(DataRaval(k:vend,1)),TempRaval(k:vend,1));
datetick('x','HHPM')
xlabel('Horas'),ylabel('Temperatura (ºC)')
title(sprintf('Març %d',floor(k/48)+1))
text(0.05,0.95,sprintf('%.2fºC',mean(TempRaval(k:vend,1),'omitnan')),...
'units','normalized','verticalalignment','top')
end
sgtitle('Temperatura dias de març')
yeah that worked. Thank you so much!!!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2021년 12월 1일

댓글:

2021년 12월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by