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 个评论

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
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 的更多信息

标签

回答:

Jan
2020-12-26

Community Treasure Hunt

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

Start Hunting!

Translated by