cell array into char
이전 댓글 표시
hi i have to create a function that allows me to create a char array containing a column of tot number, and then substitute all numbers containing 7 or that can be divided by 7 with the word 'boom'.
i have to use for loop,if else and mod.
function cellarrayN = ex8_1boom(N)
n=1:N
n=mod(n,7)
n=n(:)
celln=num2str(n)
for j=1:N
if celln(celln==0)
i dont know how to go on
댓글 수: 1
Jan
2020년 12월 26일
The question is not clear yet. A "char array" is a bad idea, mayve you mean a vector of strings or a cell string? What is "tot number"? Where are numbers coming from? Please post the original text of the question to reduce ambiguities.
답변 (1개)
Jan
2020년 12월 26일
As fas as I understand, you should create a cell array. Then do this:
cellarrayN = cell(1, N);
Maybe this cell should contain the numbers from 1 to N:
for k = 1:N
cellarrayN{k} = k;
end
Then instead of k the cell should contain the char vector 'boom', if the number is divisable by 7 or contains a 7:
s = sprintf('%g', k);
if any(s == '7') || rem(k, 7) == 0
...
end
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!