Using the listdlg index to select an array

조회 수: 7 (최근 30일)
Tobias Welby
Tobias Welby 2017년 3월 18일
댓글: Star Strider 2017년 3월 18일
Hi,
I'm a beginner at using laptop and I've hit problem with using the index value given out of the listdlg function to select an array.
I've been racking my brain how to do this, but I obviously haven't managed to get the syntax right.
Im aware it could probably be done using 'if statements,' but due to the intentions of the projects it seems a bit of a long-winded way to go about it.
Anyway, any help with this would be so greatly appreciated.
Thanks.
The code ive used so far:
MATW = {'Curtain','Glass','Plaster','Plasterboard','Wood','Acoutic Treatment'};
MATF = {'Concrete or Tile','Carpet On Foam'};
MatNumb = [1,2,3,4,5,6 ];
MatNumb(1) = [0.14 0.35 0.55 0.72 0.70 0.65];
MatNumb(2) = [0.35, 0.25, 0.18, 0.12, 0.07, 0.04];
MatNumb(3) = [0.013, 0.015, 0.02, 0.03, 0.04, 0.05];
MatNumb(4) = [0.29, 0.10, 0.05, 0.04, 0.07, 0.09];
MatNumb(5) = [0.28, 0.22, 0.17, 0.09, 0.10, 0.11];
MatNumb(6) = [0.05, 0.22, 0.52, 0.56, 0.45, 0.32];
ConcreteT = [0.01, 0.01, 0.015, 0.02, 0.02, 0.02];
CarpetF = [0.08, 0.24, 0.57, 0.69, 0.71, 0.73];
Backwall = 'Please state the area (m2) for the back wall: ';
BWA = input(Backwall);
[BWM] = listdlg('PromptString','Select Backwall Material:',...
'SelectionMode','single',...
'ListString',MATW);
BWA*MatNumb(BWM)
end

채택된 답변

Star Strider
Star Strider 2017년 3월 18일
Your approach is correct, and produces efficient code.
You need to supply a second dimension to ‘MatNumb’, then make the appropriate changes in other parts of your code.
This runs without error. I have no idea what you are doing, so I defer to you for the rest.
The (Revised) Code
MATW = {'Curtain','Glass','Plaster','Plasterboard','Wood','Acoustic Treatment'};
MATF = {'Concrete or Tile','Carpet On Foam'};
MatNumbIdx = [1,2,3,4,5,6];
MatNumb(1,:) = [0.14 0.35 0.55 0.72 0.70 0.65];
MatNumb(2,:) = [0.35, 0.25, 0.18, 0.12, 0.07, 0.04];
MatNumb(3,:) = [0.013, 0.015, 0.02, 0.03, 0.04, 0.05];
MatNumb(4,:) = [0.29, 0.10, 0.05, 0.04, 0.07, 0.09];
MatNumb(5,:) = [0.28, 0.22, 0.17, 0.09, 0.10, 0.11];
MatNumb(6,:) = [0.05, 0.22, 0.52, 0.56, 0.45, 0.32];
ConcreteT = [0.01, 0.01, 0.015, 0.02, 0.02, 0.02];
CarpetF = [0.08, 0.24, 0.57, 0.69, 0.71, 0.73];
Backwall = 'Please state the area (m2) for the back wall: ';
BWA = inputdlg(Backwall);
BWA = str2num(BWA{:});
[BWM] = listdlg('PromptString','Select Backwall Material:',...
'SelectionMode','single',...
'ListString',MATW);
Result = BWA*MatNumb(BWM,:)

추가 답변 (1개)

Tobias Welby
Tobias Welby 2017년 3월 18일
Thank you so much!
I knew that it should be possible, but was unsure of the syntax.
This has helped so much!

카테고리

Help CenterFile Exchange에서 Polymers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by