Error with parsing data from one window to another in app designer
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Kevin Holly
2022-2-23
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
更多回答(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!