make a matrix of values from questions from another matrix
3 views (last 30 days)
Show older comments
Joseph Catanese
on 27 Oct 2021
Edited: Joseph Catanese
on 27 Oct 2021
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.
0 Comments
Accepted Answer
David Hill
on 27 Oct 2021
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
David Hill
on 27 Oct 2021
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]): ');
More Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!