Print word with different name depending on the step of the cycle?

조회 수: 1 (최근 30일)
Jose Cuevas
Jose Cuevas 2021년 6월 10일
댓글: Jose Cuevas 2021년 6월 10일
I am trying to print a sentence that changes depending on the step in which the cycle is in, something like this:
for i=0:2
print '/SampleT',num2str(i),'/SampleT', num2str(i), '_530.00';
end
This is not working, I would like to have in the end up with something like this:
/SampleT0/SampleT0_530.005
/SampleT1/SampleT1_530.005
/SampleT2/SampleT2_530.005

채택된 답변

Max Heiken
Max Heiken 2021년 6월 10일
It seems you are coming from Python or similar.
The print function is not used to output text, instead use disp, fprintf, or sprintf. Also, concatenating char arrays requires rectangular brackets.
for i=0:2
disp(['/SampleT',num2str(i),'/SampleT', num2str(i), '_530.00']);
disp("/SampleT"+i+"/SampleT"+i+"_530.00");
fprintf(1, "/SampleT%d/SampleT%d_530.00\n", i, i);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by