我做這個項目,但我的講師希望它更加簡單..我試圖改變命令,但它出錯..可以請幫我..給一些線索或任何..我真的很感激,如果u能幫助我..這是問題,下面是命令。要確定最高,最低和平均根據用戶自己的選擇通過MATLAB程序的平均兩個向量的價值..如何簡化這個程序
close all
clear all
clc
disp('Welcome to my program.');
disp(' ');
disp('instruction:');
disp(' a) Enter the number of column of a vector.');
disp(' b) Next, enter the element for vector A and vector B.');
disp(' c) Then, select your option of what do you want to find.');
disp(' ');
column = input (' Enter the number of column of a vector: ');
disp(' ')
disp(' Enter the element for vector A ');
for count=1:column
disp(['A (',num2str(count), ')=']);
A(count)=input(' ');
end
disp(' ')
disp(' Enter the element for vector B');
for count=1:column
disp(['B(',num2str(count),')=']);
B(count)=input(' ');
end
disp(' ')
disp(['Vector A is [',num2str(A),')']);
disp(['Vector B is [',num2str(B),')']);
disp(' ')
disp('What do you want to find?');
disp(' ')
disp('1-find the highest value');
disp('2-find the lowest value');
disp('3-find the average value');
choose=input('Choose:');
disp(' ')
while choose >3
disp('Sorry, please enter the right input!');
choose=input('choose:');
end
disp('Your result:')
disp(' ')
fprintf('number of column:%2.0f\n',column);
disp(['vector A:[',num2str(A),']']);
disp(['vector B:[',num2str(B),']']);
if choose ==1
disp('choice: find the highest value');
elseif choose==2
disp('choice: find the lowest value');
elseif choose==3
disp('choice: find the average value');
end
switch choose
case 1
A = max(A);
B = max(B);
result=max(A,B);
case 2
A = min (A);
B = min (B);
result=min(A,B);
case 3
A = mean (A);
B = mean (B);
end
disp(['Vector A:',num2str(A)]);
disp(['Vector B:',num2str(B)]);
if choose==1
disp(['the highest value: ',num2str(result),'']);
else if choose==2
disp(['the lowest value:',num2str(result),'']);
end
end
「我試圖改變命令,但它出錯」:那你試試,它是怎樣去錯了嗎? – 2012-02-19 05:48:33