Handling UITable Cell Array

3 vues (au cours des 30 derniers jours)
Samer El Zahab
Samer El Zahab le 19 Mai 2017
Commenté : Walter Roberson le 19 Mai 2017
Hello Matlab Community,
I am trying to code the GUI for my thesis,
I used UITable, in the table I input the initial condition which is a value always, and the next column is the deterioration equation in time. Example equations: e^t, sin(t), t^2 - 2t, t and so on.
I would like to be able to create an array of equations using the the approach t0 + f(t), but UITable stores the data in cell format and thus my question is, how can I convert the data in order to utilize them effectively as equations in matlab.

Réponses (1)

Walter Roberson
Walter Roberson le 19 Mai 2017
Modifié(e) : Walter Roberson le 19 Mai 2017
In a situation like that, you would probably get() the Data property of the uitable, and then for each position where an equation was expected, using {} indexing to extract the string stored there. Then you would probably use str2func() to turn the expression into a function handle that you could execute. If you have the symbolic toolbox it can make sense sometimes to sym() the string instead of str2func() -- though using sym() for that is likely to generate a warning these days.
  2 commentaires
Samer El Zahab
Samer El Zahab le 19 Mai 2017
Modifié(e) : Walter Roberson le 19 Mai 2017
I tried your approach, but I am struggling with str2func(). completeData is the data collected from the gui, I isolated the cell columns with equations, yet for some reason I am unable to convert them to functions. The code is as follows:
functionA = completeData(:,3);
functionB = completeData(:,5);
n = size(functionA,1); %Determine total count of Data
equationsA=[];
equationsB=[];
for i = 1:1:n
equationsA = [equationsA; sym((functionA(i,1)))];
equationsB = [equationsB; sym((functionB(i,1)))];
end
Walter Roberson
Walter Roberson le 19 Mai 2017
You can replace the above with
equationsA = sym( completeData(:,3) );
equationsB = sym( completeData(:,5) );
Note that the results will be a vector of symbolic expressions, not functions. If you want symbolic functions, then
equation_vars = [x, y];
equationsA = cellfun(@(F) symfun(sym(F), equation_vars), completeData(:,3), 'Uniform', 0);
equationsB = cellfun(@(F) symfun(sym(F), equation_vars), completeData(:,5), 'Uniform', 0);
This would give you a cell array of symbolic functions. You need to store them in a cell array in order to access them individually
equationsA{1}(pi, 19) %for example

Connectez-vous pour commenter.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by