Using the listdlg index to select an array

11 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 18 Mar 2017
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,:)

Più risposte (1)

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

Categorie

Scopri di più su Biological and Health Sciences in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by