make a matrix of values from questions from another matrix

조회 수: 1 (최근 30일)
Joseph Catanese
Joseph Catanese 2021년 10월 27일
편집: Joseph Catanese 2021년 10월 27일
I am trying to get a matix that has a list of values such as [1,2,1,2] and this matrix is from a set of questions that are asked based on another matrix i.e. [1,0,1,0]. i currenty have this.
qo = 2*[1,0,1,0]; %Load Magnitude
set(0, 'DefaultUIControlFontSize', 20);
%%
%--------------------------------------------------------------------------
%. Load Choices
%--------------------------------------------------------------------------
LT1 = 1;
LT2 = 1;
LT3 = 1;
LT4 = 1;
% Section 1
if qo(1) ~= 0
LT1 = menu('Chose 1st segment load function','Constant load',...
'Linear ramp up','Linear ramp down',...
'Half sinusoid','Half cosine',...
'Gradual point load of section of segment',...
'Section of segment Load',...
'Constant load with a segment of 0',...
'Trapezoidal distribution');
end
% Section 2
if qo(2) ~= 0
LT2 = menu('Chose 2nd segment load function','Constant load',...
'Linear ramp up','Linear ramp down',...
'Half sinusoid','Half cosine',...
'Gradual point load of section of segment',...
'Section of segment Load',...
'Constant load with a segment of 0',...
'Trapezoidal distribution');
end
% Section 3
if qo(3) ~= 0
LT3 = menu('Chose 3rd segment load function','Constant load',...
'Linear ramp up','Linear ramp down',...
'Half sinusoid','Half cosine',...
'Gradual point load of section of segment',...
'Section of segment Load',...
'Constant load with a segment of 0',...
'Trapezoidal distribution');
end
% Section 4
if qo(4) ~= 0
LT4 = menu('Chose 4th segment load function','Constant load',...
'Linear ramp up','Linear ramp down',...
'Half sinusoid','Half cosine',...
'Gradual point load of section of segment',...
'Section of segment Load',...
'Constant load with a segment of 0',...
'Trapezoidal distribution');
end
LoadType = [LT1,LT2,LT3,LT4]; %Load type for LoadFunction CP
i want to simplify the LoadType variable to be a metrix of however many values there are in qo such that if qo were [1,0,1,0,1] then it would only ask the questions for qo(1) , qo(3) , qo(5) and so on. so that the Load type would then be something like [2, 1, 3, 1, 4]. i think i can use a for loop but have no idea.

채택된 답변

David Hill
David Hill 2021년 10월 27일
qo = 2*[1,0,1,0];
set(0, 'DefaultUIControlFontSize', 20);
LoadType=ones(size(qo));
for k=find(qo)
LoadType(k) = menu(sprintf('Choose %d-segment load function',k),'Constant load',...
'Linear ramp up','Linear ramp down',...
'Half sinusoid','Half cosine',...
'Gradual point load of section of segment',...
'Section of segment Load',...
'Constant load with a segment of 0',...
'Trapezoidal distribution');
end
  댓글 수: 4
David Hill
David Hill 2021년 10월 27일
Do it all at once.
qo=input('Input a binary array for whether or not the segment is needed (for example: [1 0 1 0]): ');
Joseph Catanese
Joseph Catanese 2021년 10월 27일
편집: Joseph Catanese 2021년 10월 27일
how would i set up a matrix that is of strings such that lt = ['constant', 'linear ramp up','constant','constant'] depending on what choices were selected

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by