Using the drop down box in app designer
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I am trying to assign values to different options in a drop down menu and then calculate reverb time using a formula. It is spitting out the wrong values as it is not recognising CA, WA and FM (only starting off so sorry if its blindingly obvious)
% Button pushed function: Button2
function Button2Pushed(app, event)
value = app.WallMaterialDropDown.Value;
value = app.FloorMaterialDropDown.Value;
value = app.CeilingMaterialDropDown.Value;
WA = app.WallMaterialAbsoprtionCoeffecientEditField.Value;
CA = app.CeilingMaterialCoeffiicientEditField.Value;
FA = app.FloorMaterialCoefficientEditField.Value;
if app.FloorMaterialDropDown.Value == strcmp(value,'Concrete or Tile')
FA = 0.02;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'Linoleum/ Vinyl Floor On Concrete')
FA = 0.03;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'Wood on Joists')
FA = 0.07;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'Parquet on Concrete')
FA = 0.06;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'Carpet on Concrete')
FA = 0.37;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'Carpet on foam')
FA = 0.69;
app.FloorMaterialCoefficientEditField.Value = FA;
elseif app.FloorMaterialDropDown.Value == strcmp(value,'6mm carpet')
FA = 0.31;
app.FloorMaterialCoefficientEditField.Value = FA;
end
if app.WallMaterialDropDown.Value == strcmp(value,'Brick Unglazed')
WA = 0.04;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Sheetrock 1/2"')
WA = 0.04;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Wood 3/8 Plywood Panel')
WA = 0.09;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Marble and Tile ')
WA = 0.01;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Plaster Rough on Lath')
WA = 0.05;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Plaster Smooth On Brick')
WA = 0.03;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Glass: Window')
WA = 0.12;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Foam: Polyur 1"')
WA = 1.00;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Foam Polyur 1/2"')
WA = 0.60;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Glass 1/4 large plate')
WA = 0.03;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Foam SDG 3"')
WA = 0.91;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Foam SDG 4"')
WA = 0.99;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Fiberglass 5" sprayed')
WA = 0.70;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Fibreglass 2" rolls')
WA = 0.90;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Foam Sonex 2"')
WA = 0.81;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Fiberglass 1" sprayed')
WA = 0.90;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Fiberglass ')
WA = 0.99;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value,'Curtain 18oz')
WA = 0.72;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Fiberglass 2" No gaps')
WA = 0.99;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Curtain 14"')
WA = 0.75;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Brick Unglazed and Painted')
WA = 0.02;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Concrete Block Coarse')
WA = 0.29;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Concrete Block Painted')
WA = 0.07;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Curtain 10oz')
WA = 0.17;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Rockwool')
WA = 0.9;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
elseif app.WallMaterialDropDown.Value == strcmp(value, 'Hard Surface')
WA = 0.03;
app.WallMaterialAbsoprtionCoeffecientEditField.Value = WA;
end
if app.CeilingMaterialDropDown.Value == strcmp(value,'Acoustic Tiles')
CA = 0.56;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Acoustic Ceiling Tiles')
CA = 0.92;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Fibreglass 2" no airspace')
CA = 0.99;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Fibreglass Spray 5"')
CA = 0.70;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Fibreglass spray 1"')
CA = 0.90;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Fibreglass Rolls 2"')
CA = 0.90;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'wood')
CA = 0.07;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Foam Sonex 2"')
CA = 0.81;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Foam SDG 3"')
CA = 0.91;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Foam SDG 4"')
CA = 0.99;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value,'Foam Polyur 1"')
CA = 1.00;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Foam Polyur 1/2"')
CA = 0.60;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'Plaster smooth on brick')
CA = 0.03;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value,'Plaster rough on lath')
CA = 0.05;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value,'Sheetrock 1/2"')
CA = 0.04;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value, 'wood 3/8"')
CA = 0.09;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
elseif app.CeilingMaterialDropDown.Value == strcmp(value,'Hard Surface')
CA = 0.03;
app.CeilingMaterialCoeffiicientEditField.Value = CA;
end
% think this may be the problem
app.AreaofAbsorptionSaEditField.Value = (app.FloorEditField.Value + FA) + (app.WallsEditField.Value + WA) + (app.CeilingEditField.Value + CA); %
c = 0.161;
a = (app.RoomVolumeEditField.Value/app.AreaofAbsorptionSaEditField.Value);
app.RT60EditField.Value = c/a;
0 comentarios
Respuestas (1)
Adam Danz
el 31 de Mzo. de 2020
Editada: Adam Danz
el 31 de Mzo. de 2020
Problems:
1. You've got 3 variables named "value" and they all have the same value which is equal to the last of those variables since you're overwriting the first two.
2. Instead of a bunch of if/else, use a switch, case, otherwise. It's much more organized and efficient.
3. strcmp() returns a logical array where true values mark matches. Is that really what's stored in app.FloorMaterialDropDown.Value, a logical value? If so, just use
if app.FloorMaterialDropDown.Value && strcmp(value,'Concrete or Tile')
% or, if you're expecting a non-scalar
if app.FloorMaterialDropDown.Value & strcmp(value,'Concrete or Tile')
% but I doubt this is what's stored in the dropdown menu....
4. Usually case sensitivity is not desired. If this is the case for you, use strcmpi() instead of strcmp() so "concrete..." can be matched with "Concrete...".
5. Regarding the comment you left pointing to the line that you think is causing the problem, put a breakpoint at that line in your App code so that execution is paused and evaluate the values of each variable. I think you'll see that the problem is within your conditionals (which should be changed to switch/case).
2 comentarios
Adam Danz
el 1 de Abr. de 2020
Please take a few minutes to look through the documentation for strcmp. You're using it incorrectly. Also see the examples on that page.
In fact, you don't need strcmp if you're using a switch/case
FA = app.FloorMaterialCoefficientEditField.Value;
switch FA
case 'Concrete or Tile'
FA = 0.02;
case 'Linoleum/ Vinyl Floor On Concrete'
FA = 0.03;
case 'Wood on Joists'
FA = 0.07;
Ver también
Categorías
Más información sobre Oceanography and Hydrology en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!