How to call array with string
Show older comments
Hello,
I'm writing a Matlab App Designer program to help visualize my Data.

Since there are a lot of different settings and therefore a whole lot Data to plot I created an array containing all of my processed Data and it's variations ('Datenbank.mat').
Now I want to be able to set what Data I want to plot on the left, then click the Button 'plot' and get my desired graph.
For this I tried using the user input as indices, so I can use them to acces the needed data from my struct array 'datenbank'. The following code should represent what I'm trying to do:
properties (Access = private)
datenbank = load('Datenbank.mat'); % Description
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: plotButton
function plotButtonPushed(app, event)
index1 = app.VersuchsnummerEditField.Value;
index2 = str2num(app.DurchlaufDropDown.Value);
[~,index3] = ismember(app.MessgreDropDown.Value, app.MessgreDropDown.Items);
[~,index4] = ismember(app.TypDropDown.Value, app.TypDropDown.Items);
[~,index5] = ismember(app.AbschnittDropDown.Value, app.AbschnittDropDown.Items);
titel = {'ges','e','m','a','fft_ges','fft_e','fft_m','fft_a'};
index5 = titel(index5);
[~,index6] = ismember(app.FilterungDropDown.Value, app.FilterungDropDown.Items);
% Create Variable name !! My Problem !!
x = {'app.datenbank.datenbank(' index1 ').Plots(1).Index.' index5};
y = {'app.datenbank.datenbank(' index1 ').Plots(' index2 ').Data(' index3 ').' index5};
plot(app.UIAxes,x,y,'-r');
end
end
Since this is not the right syntax it doesn't work, but I know that when I insert a variable name from my data array for x and y I get my desired graph so I just need to implement proper naming of the variable. The problem lies within 'index5' since I need to set it to the right string to call the correct array. I know that naming variables dynamically is not recommended in Matlab, so I'm open to suggestions to solve this whole thing in another way.
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!