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 comentario

Jan
Jan el 26 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 26 de Dic. de 2020

0 votos

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

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Dic. de 2020

Respondida:

Jan
el 26 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by