Я сделал эту программу, но мой лектор хотел бы, чтобы это было проще. Я попытался изменить команду, но она пойдет не так .. может, пожалуйста, помогите мне .. дайте подсказку или что-то еще .. я действительно ценю, если и может помочь мне .. это вопрос, а ниже - команда. Чтобы определить наивысшее, низкое и среднее значение двух векторов в зависимости от собственного выбора пользователем по среднему программированию 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
«Я попытался сменить команду, но все идет не так»: что вы пытались и как это случилось? –