Using App Designer: Pulling data from an X,Y indices from a user input in 2 drop down menus

4 visualizzazioni (ultimi 30 giorni)
Hello!
see my update below with errors
Okay, now I am getting these errors in the command window (may have been getting them the whole time, just didn't realize it). I'm off to see if I can figure this out, but any help would be greatly appreciated! Thanks!
Incorrect number or types of inputs or outputs for function 'FluxDataPulled'.
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating DropDown PrivateDropDownOpeningFcn.
Incorrect number or types of inputs or outputs for function 'FluxDataPulled'.
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Incorrect number or types of inputs or outputs for function 'FluxDataPulled'.
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
end update
Attached is my .m file and my spreadsheet. I have my whole tool working, except I am trying to pull data from a spreadsheet, I have in the right file path. I do not get any errors when I run it, however, when I select the "Flux" button, nothing happens. The rest of the tool works as long as I manually enter in the flux. Below is a c/p of the code from this portion, and in the .m file it's in lines 39 through 87. I have a feeling i'm not "reading" the table correctly. I've tried many variations of this including:
Table = readtable('FluxDataInterpolated.xlsx','Sheet1',false);
Table = readtable('FluxDataInterpolated.xlsx','Sheet1',true);
Table = readtable('FluxDataInterpolated.xlsx','Sheet1','Data');
properties (Access = private)
inclination
altitude
flux
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
Table = readtable('FluxDataInterpolated.xlsx','Sheet1','Data');
app.inclination = Table{1,2:end};
app.altitude = Table{2:end,2};
app.flux = Table{:,3};
app.DisplayFlux.Value = app.flux(1);
end
% Drop down values for Inclination and Altitude
function InclinationDegDropDownValueChanged(app, ~)
xvalue = app.InclinationDegDropDown.Value;
yvalue = app.AltitudekmDropDown.Value;
xindices = find(app.inclination==str2double(xvalue));
yindices = find(app.altitude==str2double(yvalue));
idx=intersect(xindices,yindices);
app.DisplayFlux.Value = app.flux(idx);
end
function AltitudekmDropDownValueChanged(app, ~)
xvalue = app.InclinationDegDropDown.Value;
yvalue = app.AltitudekmDropDown.Value;
xindices = find(app.inclination==str2double(xvalue));
yindices = find(app.altitude==str2double(yvalue));
idx=intersect(xindices,yindices);
app.DisplayFlux.Value = app.flux(idx);
end
% Push Flux button to Display Flux from table
function Fluxdatapulled(app, ~)
xvalue = app.InclinationDegDropDown.Value;
yvalue = app.AltitudekmDropDown.Value;
xindices = find(app.inclination==str2double(xvalue));
yindices = find(app.altitude==str2double(yvalue));
idx=intersect(xindices,yindices);
app.DisplayFlux.Value = app.flux(idx);
end
end

Risposte (1)

Walter Roberson
Walter Roberson il 19 Ago 2023
Table = readtable('FluxDataInterpolated.xlsx', 'Sheet', 'Sheet1');
Note that the file only has one sheet, and the default for readtable is to read the one sheet, so you could just use
Table = readtable('FluxDataInterpolated.xlsx');
It is not clear to me why you are not using readmatrix as I had suggested before.
  9 Commenti
Walter Roberson
Walter Roberson il 21 Ago 2023
xvar = find(inclination==xvalue);
You expect that to return a scalar.
yvar = find(altitude==yvalue);
You expect that to return a scalar.
Int = find(xvar,yvar);
The first input to find() is expected to be a scalar there.
The basic operation of find() is to look for non-zero entries in the first parameter and return the indices of those non-zero values. find() never returns 0 because 0 is not a possible index.
Since xvar is the result of a find() call, xvar would be a list of zero or more positive values -- expected to be exactly one non-zero value. So none of the entries in xvar can be 0, and so when you ask to find the indices of the non-zero entries in xvar then that is going to be the indices of all (typically 1) entries in xvar.
When you pass a second parameter to find(), that limits the number of indices returned to be no more than the given number. For example, find(XYZ, 3) would ask for at most the first three non-zero entries of XYZ.
We are expecting xvar to be scalar, so we are expecting there to be only one entry to find the index of, so we are not expecting the limit being expresed through yvar to have any effect.
Taking again the example I did before: you might find() that the inclination of the drop-down box might correspond to row 3 of the table, and you might find() that the altitude corresponded to column 5 -- so you would be asking for Int = find(3, 5) which asks for at most the first 5 indices of the non-zero entries in the scalar 3 . We would therefore expect that Int will store 1 almost all of the time.
What can change that? Well, if inclination and xvalue are character vectors then you would likely have trouble. Consider that '1' == '10' is not going to return a scalar false and would instead return the vector [true false] -- because == between character vectors tries to compare each character against the respective character in the other vector if both entries are non-scalar, and if one of the entries is scalar then that scalar will be compared against each entry in the other. '10' is not a scalar, it is a vector, ['1' '0']
Do not use == to compare entries that are intended to represent groups. Use strcmp() or strcmpi() . Or make sure you are using string() objects: "1" == "10" does check to see whether the group 1 matches the group 10 as a whole.
But none of this would be necessary if you were to do what I recommended earlier and configured the ItemsData values to be directly the row number or column number to be used: then you would use the values directly as indices.

Accedi per commentare.

Categorie

Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by