cell array into char
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 26 Dez. 2020
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.
Antworten (1)
Jan
am 26 Dez. 2020
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
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!