How to convert a flowchart into a code

조회 수: 28 (최근 30일)
Raizel Lampert
Raizel Lampert 2021년 7월 29일
편집: Yazan 2021년 7월 29일
  댓글 수: 3
Raizel Lampert
Raizel Lampert 2021년 7월 29일
Is there a possibility of receiving steps as I am like a newborn on MATLAB
Yazan
Yazan 2021년 7월 29일
See the code in the answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yazan
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)
Array s = [16 25 36 49 64 ]
fprintf(fmt, 'c', c)
Array c = [64 125 216 343 512 ]
fprintf(fmt, 'f', f)
Array f = [256 625 1296 2401 4096 ]

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by