make a matrix of values from questions from another matrix

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.

 Accepted Answer

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 Comments

how would i do this for qo now such that it asks yes or no 1 being yes and 0 being no
ie initalize qo as zeros(1,4) or zeroa(1,5)
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]): ');
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

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!