How to convert a flowchart into a code
9 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/697987/image.png)
3 件のコメント
回答 (1 件)
Yazan
2021 年 7 月 29 日
編集済み: Yazan
2021 年 7 月 29 日
clc, clear,
% If you want the user to enter the vector x, then uncomment the lines 6 to 14
% and comment the line 16
% x = input('Enter an array of 5 numbers \n');
%
% if ~isnumeric(x)
% error('Enter a numeric array')
% end
%
% if length(x)<5
% error('Enter an array of five numbers')
% end
x = 4:8;
k = 1;
s = nan(1, 5);
c = nan(1, 5);
f = nan(1, 5);
while k<=5
s(k) = x(k).^2;
c(k) = x(k).^3;
f(k) = x(k).^4;
k = k+1;
end
fmt = ['\n Array %s = [' repmat('%g ',1, numel(s)) ']\n'];
fprintf(fmt, 's', s)
fprintf(fmt, 'c', c)
fprintf(fmt, 'f', f)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!