plotting title with multiple strings on one line

hi guys,
i've been searhing through the community responses and google and can't find an answer so i'll ask the question here.
i have two strings that i'd like to plot both of them on the plot title in one line. i've tried using stringEASY=strcat("a ","b") then title(stringEASY) and that works, but that's not what i have, here's what i have:
str_cell_array1 = str_cell_array(1,1) in the command window looks like a 1X1 cell array {["abc\_def.h5"]}
str_cell_array2 = str_cell_array(1,2) in the command window looks like a 1X1 cell array {["ghi\_jkl.h5"]}
if i use title("abc\_def.h5","ghi\_jkl.h5") i of course get a plot but the "ghi\_jkl.h5" is a subtitle which i don't want
so i've tried to cat the two together as
string=strcat(str_cell_array1,str_cell_array2)
which in the command window looks like string = {["abc\_def.h5" "ghi\_jkl.h5"]}
and then title(string) but that doesn't work
i've also tried string=strcat({'str_cell_array1'},{'str_cell_array2'})
and then title(string) but that also doesn't work
any hints?
Todd

 채택된 답변

Voss
Voss 2022년 5월 13일
편집: Voss 2022년 5월 13일
str_cell_array = {"abc\_def.h5" "ghi\_jkl.h5"};
str_title = strjoin(string(str_cell_array)," and ")
str_title = "abc\_def.h5 and ghi\_jkl.h5"
title(str_title);
figure
str_cell_array = {"abc\_def.h5" "ghi\_jkl.h5" "mno\_pqr.h5"};
str_title = strjoin(string(str_cell_array),", ")
str_title = "abc\_def.h5, ghi\_jkl.h5, mno\_pqr.h5"
title(str_title);

추가 답변 (2개)

Jonas
Jonas 2022년 5월 13일
편집: Jonas 2022년 5월 13일
this works for me
title("abc\_def.h5" + " and " + "ghi\_jkl.h5");
a concatenated string in one line

댓글 수: 3

Dolly More
Dolly More 2022년 7월 11일
편집: Dolly More 2022년 7월 11일
Is there any way to put multiple strings on different location (left corner, middle and right corner) in title?
I have 4 strings of correlation values of different section of the time series which I want to put above those sections. Is it possible to do in matlab?
Right now I am just using the value and adding spaces to seperate them which isn't working the way I want it to.
title(['R = - 0.40 ', '{\color{red} R = -0.19 ',...
'\color{blue} R = 0.43 ', '\color{green} R = 0.37}']);
you could abuse latex interpreter to create a table in the title, you can set fixed to each column to stretch it as far as wished
plot(1:3);
title('\centering \begin{tabular}{p{3cm} p{3cm} p{3cm}} top left & top center & top right \\ bottom left & bottom center & bottom right \end{tabular}','Interpreter','latex')
you could also set alignment per column, but then you cannot set the column width
figure; plot(1:3)
title('\begin{tabular}{lcr} top left & top center & top right \\ bottom left & bottom center & bottom right \end{tabular}','Interpreter','latex')
but you could add white space (here \hspace - horizontal space) or empty column for additional spacing
figure; plot(1:3)
title('\begin{tabular}{lcr} top left & top center & top right \\ bottom left \hspace{1cm} & bottom center & \hspace{1cm} bottom right \end{tabular}','Interpreter','latex')
Thank you @Jonas. It works perfect!!

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

Adam Jurhs
Adam Jurhs 2022년 7월 11일

0 개 추천

that's pretty fancy, but latex is WAAAAY over my head, and the answer to my question has already been posted, thanks
Todd

댓글 수: 2

Jonas
Jonas 2022년 7월 12일
actually my comment was just the answer to the comment of @Dolly More, I just realized it has nothing to do with your question ;-)
I am sorry for posting a different question here. But I didn't want to create multiple questions which were on the similar line.

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

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 5월 13일

댓글:

2022년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by