How to import matrix to app designer?
    28 views (last 30 days)
  
       Show older comments
    
    Batia Friedman-Shaw
 on 20 Feb 2018
  
    
    
    
    
    Commented: Lui
 on 15 May 2019
            I have a cell array in my matlab workspace. How do I import it or use its data in code written in app designer?
0 Comments
Accepted Answer
  Prajith Chilummula
      
 on 22 Feb 2018
        
      Edited: Prajith Chilummula
      
 on 22 Feb 2018
  
      Before 2017b,there was a workaround to pass data from workspace to appdesigner. Please refer this link for the method:
https://www.mathworks.com/matlabcentral/answers/284140-call-an-mlapp-with-input-argument-s
In 2017b,the problem is resolved:
1) If you want to share/load data from outside the app, try the following:
   a) You can load data from a MAT file in appdesigner code as shown below (inside a 
      callback function):
      >> mydata = load('data.mat'); % This will load all the variables in data.mat to 
                                      mydata structure
   b) If you would like to load your data at the initialization phase of the app, add 
      the above code in "startupFcn" callback of the app.
   c) You can read data from base workspace as shown below.
     >> data = evalin('base','varName'); % varName is in MATLAB base workspace
        https://www.mathworks.com/help/matlab/ref/evalin.html
2) If you want to share data among callbacks of the app, you can create additional public/private properties of the app and store data in these proprieties.
    Refer to the following documentation page for additional information on this.
    https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
3) If you want to pass data from app to other external function or to the base workspace, you can do this as shown below:
   >> app = myTestApp; % call app and assign to a variable
   >> % Retrieve public properties (x,y) of the app
   >> x = app.x;
   >> y = app.y;
2 Comments
  Alastair Punler
 on 3 Apr 2019
				Hi I am having issues using the evalin method, it still returns an error as undefined variable.
I am trying to use a slider to plot different rows in the waterfrontstore matrix which i am trying to import from the matlab workspace after the simulation is run by pressing the button. 
        % Value changed function: Slider
        function SliderValueChanged(app, event)
            value = app.Slider.Value;
            i=value+1;
            y=water(:,i)
            x=1:1:numlayers
           plot(app.UIAxes,y,x)
        end
        % Button pushed function: SimulateButton
        function SimulateButtonPushed(app, event)
            %% runs a simluation script that one of the outputs is waterfontstore which is a 1000x20 matrix
            water = evalin('base','waterfrontstore')
        end
        end
after the simulation is run i would like my entire workspace to be available to use when the slider is moved or other call backs are used? 
  Lui
 on 15 May 2019
				I can see you have not specified your plotting function. Would also like to assume that you have an axis where you would like to plot your data on.
% Button pushed function: SimulateButton
        function SimulateButtonPushed(app, event)
            %% runs a simluation script that one of the outputs is waterfontstore which is a 1000x20 matrix
            water = evalin('base','waterfrontstore')
            water(:,i)=y;
            x=1:1:numlayers;
           plot(app.UIAxes,y,x)
        end
        end
        end
What I undertsand is that you cannot call a variable before it is defined. So you ought to call Water first as above. 
Secondly you could state the different cases if they are not many using an if ; if else to pick different values
More Answers (1)
  Savannah Morrissey Martin
 on 31 May 2018
        How do you access different elements of the cell once it is imported?
0 Comments
See Also
Categories
				Find more on Text Files 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!



