make a matrix of values from questions from another matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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]): ');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!