Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to coampre strings and print

조회 수: 1 (최근 30일)
Lee
Lee 2013년 11월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
hello im supposed to create a function that gets input of a month and year and im supposed to get output prinnted my problem is that every time the function gets to dates like 10 or 20 it only prints 1 2 so instead of 11 12 13 14...i get 1 12 13 14... i tried doing if w(i,j)='10' fprintf('10') but it says it is not possible to compare strings im not aloowed to usestrcmp
function fprintfmatrix(mat)
w=num2str(mat);
rows=size(w,1);
col=size(w,2);
for i=1:rows;
for j=1:col;
if w(i,j)~='0'
fprintf(w(i,j))
elseif w(i,j)=='0';
fprintf(' ')
end
end
fprintf('\n')
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 20일
num2str never includes leading '0' when you use it in that form, so there would not seem to be any good reason to emit a blank instead of a 0.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by