Azzera filtri
Azzera filtri

Matlab GUI design. Apply logical indexing expression to a loaded file using input values

1 visualizzazione (ultimi 30 giorni)
Hi,
i'm writing a simple GUI that has to be capable of loading a file (this part i already managed), receiving two values from differents EditField and use those values on a logical indexing expression applied to the loaded file. Tipically a row selection on a matrix activated with a "Apply cut" button.
I'm using App Designer on Matlab R2020b.
I've already created all the button and fields. The file is correctly loaded via this function:
function LoadfileButtonPushed(app, event)
[file,path] = uigetfile('*.geo.txt');
if isequal(file,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,file)]);
end
R=dlmread(fullfile(path , file), ";", 4, 0);
end
and the extremes of the cut are read by those functions:
function toEditFieldValueChanged(app, event)
to_value = app.toEditField.Value;
end
function FromEditFieldValueChanged(app, event)
from_value = app.FromEditField.Value;
end
Last, the function related to the "apply cut" button is:
function ApplycutButtonPushed(app, event)
R_mod=R(from_value:to_value, :);
end
My problem is that those function does not communicate, and the "Code View" function does not allow me to write a "main function" in which make those functions work together.
Any help would be very appreciated,
thanks in advance.

Risposte (2)

Mario Malic
Mario Malic il 5 Feb 2021
Modificato: Mario Malic il 5 Feb 2021
Hi Alessandro,
yes, these callbacks do not communicate. You can solve this in a much simpler way, remove 'to' and 'from' callbacks completelly.
You don't need to create a callback to be able to track the property values in the component.
function ApplycutButtonPushed(app, event)
to_value = app.toEditField.Value;
from_value = app.FromEditField.Value;
R_mod=R(from_value:to_value, :);
end
If you have a more complicated case, where you'd do some calculations inside a callback, you can create a property that you'll assign the calculated value. Property is accessible everywhere within and outside of app (if properties are declared as public). You set/access the property values indexing into app like shown in callback.
properties(access = private)
R
end
function SomeCallback(app,event)
app.R=dlmread(fullfile(path , file), ";", 4, 0);
end
Edit: you could use the same principle as I've just mentioned just above this line which I've just edited.

Alessandro Togni
Alessandro Togni il 5 Feb 2021
This solves a big part of the problem, but still the variable R created on the LoadfileButtonPushed function is not reacheable in ApplycutButtonPushed.

Categorie

Scopri di più su Develop Apps Using App Designer 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