Matlab GUI design. Apply logical indexing expression to a loaded file using input values
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
Mario Malic
2021년 2월 5일
편집: Mario Malic
2021년 2월 5일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!