Error with parsing data from one window to another in app designer

1 view (last 30 days)
Hello All,
Ik keep having the error "Unable to use a value of type Analyzer as an index.". Even though Analyzer is not a Variable or Function it is the name of my MainApp. I would like to snd data from one window to another and thought I had done all correct and now I get this error but I don't kno wwhere to look anymore cause I dont understand this has something to do with indexing. So Ill show my code below and maybe someone could point me out what I do wrong.
First some properties which I have in the MainApp called "Analyzer
properties (Access = private)
frmPreferences;
X1; %X1 = raw selected data from Load data class
X2;
Y1; %Y1 = raw selected data from Load data class
Y2; %Y2 = raw selected data from Load data class
YBprocessed;
YRprocessed;
Xprocessed;
StartSample;
EndSample;
SampleFrequency;
FileName;
CallData;
end
Then When I would press on the menubar the option "Preferences" I want another window opens. In this case it sends from the main window to the Preference Window a number (SampleFrequency). This is for testing purposes
function PreferencesMenuSelected(app, event)
t = num2str(app.SampleFrequency);
app.frmPreferences = app.frmPreferences(app, t);
end
Next the code in the second window called "frmPreferences" with its properties
properties (Access = private)
Callingapp;
end
And the code when the window get opened:
function startupFcn(app, Analyzer, DatafrmAnalyzer)
app.Callingapp = Analyzer;
app.lblSampleFreq.Text = DatafrmAnalyzer;
end
I have also tried to rename Analyzer but this dont make any differences. So I hope someone can help me a bit.
Thanks in advance

Accepted Answer

Kevin Holly
Kevin Holly on 23 Feb 2022
I like to keep things simple and just read from main app.
Main app (Analyzer):
properties (Access = private)
frmPreferences;
X1; %X1 = raw selected data from Load data class
X2;
Y1; %Y1 = raw selected data from Load data class
Y2; %Y2 = raw selected data from Load data class
YBprocessed;
YRprocessed;
Xprocessed;
StartSample;
EndSample;
SampleFrequency;
FileName;
CallData;
end
function PreferencesMenuSelected(app, event)
app.frmPreferences = frmPreferences(app);
end
frmPreferences:
properties (Access = private)
Callingapp;
end
function startupFcn(app, Analyzer)
app.Callingapp = Analyzer;
app.lblSampleFreq.Text = num2str(app.Callingapp.SampleFrequency);
end
OR
If you need to use t again, you could save it as a property of the main app.
Main app (Analyzer):
properties (Access = private)
frmPreferences;
X1; %X1 = raw selected data from Load data class
X2;
Y1; %Y1 = raw selected data from Load data class
Y2; %Y2 = raw selected data from Load data class
YBprocessed;
YRprocessed;
Xprocessed;
StartSample;
EndSample;
SampleFrequency;
FileName;
CallData;
t
end
function PreferencesMenuSelected(app, event)
app.t = num2str(app.SampleFrequency);
app.frmPreferences = frmPreferences(app);
end
frmPreferences:
properties (Access = private)
Callingapp;
end
function startupFcn(app, Analyzer)
app.Callingapp = Analyzer;
app.lblSampleFreq.Text = app.Callingapp.t;
end
  1 Comment
Raymond Gilbers
Raymond Gilbers on 23 Feb 2022
ahhh thanks a lot I even did not know I could call variable from the main app with the syntaxis
app.Callingapp.t
Much appreciated!

Sign in to comment.

More Answers (0)

Categories

Find more on Timetables in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!