Graph tiltle with multiple variables over 2 lines

I Have been tryint to make the variables contained in this title append over two maybe three lines, following the use of {} brackets. But so far it returns 3 per lines per num2str. Could anyone help point appropriate corrections to obtain 2 maybe three lines.
thanks
title({'Request dur= ' num2str(timeseriesMatPurgeRequest{II}{X}.time(end)),'s, Request Dist = ' num2str(timeseriesMatPurgeRequestvalues(1)),'km', 'NOx eff = ' num2str(((timeseriesMatPurgeRequestvalues(1)-timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(end))/timeseriesMat.values(1))*100) '%, Dilution = ' num2str(((timeseriesMatPurgeRequest.values(1)-timeseriesMatPurgeRequest{II}{X}.elomm_w_fio_out_01.signals.values(end))/timeseriesMatPurge.values(1))*100) '%','AcvRul = ' num2str(timeseriesMatPurgeRequest.values(1)) ', Total Rich Time = ' num2str(sum(mode(diff(timeseries.time))*numel(find(timeseriesMat.values<1)))) 's', 'NOx Remove Rate = ' num2str(((timeseriesMatvalues(1)-timeseriesMat.values(end))/(sum(mode(diff(timeseriesMatPurge.time))*numel(find(timeseriesMat.values<1))))))'})

 채택된 답변

Geoff Hayes
Geoff Hayes 2019년 4월 27일
Franc - try using sprintf to create one or more lines that you can use in your title. For example,
myTitle = sprintf('first row has integer: %d\nsecond row has float: %f\n', 42, pi);
title(myTitle);
Note how you do not have to convert any of your numbers into strings (the '\n' is used to indicate a new line). You may want to use local variables for the calculated values rather than trying to do them all on one line of code. i.e.
totalRichTime = sum(mode(diff(timeseries.time))*numel(find(timeseriesMat.values<1)));
duration = timeseriesMatPurgeRequest{II}{X}.time(end);
myTitle = sprintf('duration = %fs\ntotal rich time = %fs', duration, totalRichTime);
or something similar.

댓글 수: 9

Franc
Franc 2019년 4월 27일
편집: Franc 2019년 4월 27일
Great thanks, ill give it a try and respond
Franc
Franc 2019년 4월 27일
This solution has not worked out, it results is a repeat of a single variable across the plot
please show your code and/or describe what you mean by a repeat of a single variable across the plot...
Franc's answer moved here
Hi
my code is as below, ultimately i'm looking to have max3 variables per line but the resultant variable of the just the one in the sprintf repeats 3 times on the graph and other line do not show. so maybe i have the syntax wrong.
Requestdur= num2str(timeseriesMatPurgeRequest{II}{X}.ATSys_noATSysRgnReq.time(end));'s';
RequestDist = num2str(timeseriesMatPurgeRequest{II}{X}.OdometerMasterValue.signals.values(1)); 'km';
NOxeff = num2str(((timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(1)-timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(end))/timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(1))*100); '%';
Dilution = num2str(((timeseriesMatPurgeRequest{II}{X}.elomm_w_fio_out_01.signals.values(1)-timeseriesMatPurgeRequest{II}{X}.elomm_w_fio_out_01.signals.values(end))/timeseriesMatPurgeRequest{II}{X}.elomm_w_fio_out_01.signals.values(1))*100); '%';
AcvRul = num2str(timeseriesMatPurgeRequest{II}{X}.ATSys_noRgnAcvRul.signals.values(1));
TotalRichTime = num2str(sum(mode(diff(timeseriesMatPurgeRequest{II}{X}.LSU_rLam__0_.time))*numel(find(timeseriesMatPurgeRequest{II}{X}.LSU_rLam__0_.signals.values<1)))); 's';
NOxRemoveRate = num2str((timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(1)-timeseriesMatPurgeRequest{II}{X}.ExM_mStrNOx_ExEle.signals.values(end))/(sum(mode(diff(timeseriesMatPurgeRequest{II}{X}.LSU_rLam__0_.time))*numel(find(timeseriesMatPurgeRequest{II}{X}.LSU_rLam__0_.signals.values<1)))));'g/s';
myTitle = sprintf('Requestdur = %fs' ,Requestdur);
title(myTitle);
Geoff Hayes
Geoff Hayes 2019년 4월 28일
편집: Geoff Hayes 2019년 4월 28일
Hi Franc - since we are using sprintf and %f, this means that we don't have to conver the Requestdur to a string. So we can simply do
Requestdur = timeseriesMatPurgeRequest{II}{X}.ATSys_noATSysRgnReq.time(end);
myTitle = sprintf('Requestdur = %fs' ,Requestdur);
title(myTitle);
If it still prints three lines, then this could be because of the data. Is Requestdur a scalar or is it an array?
As for the other lines do not show, I don't know what you mean by this. Do you mean the other variables don't show? If that is the case, then that makes sense since you are only writing/including Requestdur in your title...and not the others.
Franc
Franc 2019년 4월 28일
Hi Geoff, added a screen shot of the result of the one line sprintf.
so you can see what the issue is, this is subplot of variable quantity and each one would have the same format output.
Hi Franc - so it looks like your Requestdur is an array. Is that what you are expecting?
With the (end) indexing at the end of timeseriesMatPurgeRequest etc., then Requestdur would have to be a scalar. If II was non-scalar or X is non scalar or ATSys_noATSysRgnReq is a non-scalar structure, then you would have received a runtime error about attempting to index improperly. The only way you could get Requestdur as a vector there without significant changes to the code is if you omitted the (end) indexing.
Franc
Franc 2019년 4월 28일
편집: Franc 2019년 4월 28일
Geoff/Walter, I was reading the documentation a bit more i realised I could use [ ] within the { } to partition the code and then using ; between the [ ] to add another line.
So really appreciate your helping me think through it. Sample added.

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

추가 답변 (0개)

질문:

2019년 4월 27일

편집:

2019년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by