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 commentaire

Jan
Jan le 26 Déc 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.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 26 Déc 2020

0 votes

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

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by