MATLAB Answers

Solving Symbolic Equations with Solve-Creating a GUI

4 views (last 30 days)
Junior Aguilar
Junior Aguilar on 17 Jan 2020
Commented: Junior Aguilar on 18 Jan 2020
I am creating a program (GUI) in Matlab and so in one part I need to solve a system of symbolic "n" equations (introduced by the user) unknowns. The code that I have generated works correctly, because I have checked the results, but these(the results) are shown in the form of a structure of symbolic elements and to be able to see each one, I need to write the name of the structure and the field and this is the PROBLEM! I have to make the results be shown and stored in an array or vector (because they are numbers) but with a for-cycle or any other, because I can't be writing 1 by 1 to see the results. Please if anyone can help me, I would appreciate it! Thank you.
Sistema_1=Ecuaciodiv_1a(2:filas,1)-Ecuaciodiv_2a(1:filas-1,1)
Sistema_2=Ecuaciodiv_1b(2:filas,1)-Ecuaciodiv_2b(1:filas-1,1)
for p=Puntos_Apoyo
Ecuaciones_3a=Ecuaciones_1b(p);
end
Sistema_3=Ecuaciones_3a
rptas=solve([Sistema_1,Sistema_2,Sistema_3])
rptas.c1
rptas.c2
rptas.c3
rptas.c4
rptas.c5
rptas.c6
rptas.c7
rptas.c8
rptas.c9
rptas.c10
rptas.c11
rptas.c12
rptas.c13
rptas.c14
rptas.c15
rptas.c16
rptas.c17
rptas.c18
Attached are some images.
guide.png

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 Jan 2020
temp = struct2cell(rptas);
results = vertcat(temp{:});
However, you need to be careful with this, as the order of fields in rptas is not necessarily the same as you are expecting. The order used is not documented, and depending on version might or might not be the same as is used by symvar() . Remember that symvar() would use the order c1 c10 c11 c12 c13 c14 c15 c16 c17 c18 c2 c3 c4 c5 c6 c7 c8 c9
You are probably better off constructing a cell array of character vectors in the order you want the fields, and loop, something like
fieldorder = {'c1' 'c2' 'c3' 'c4' 'c5' 'c6' 'c7' 'c8' 'c9' 'c10' 'c11' 'c12' 'c13' 'c14' 'c15' 'c16' 'c17' 'c18'};
for K = 1 : length(fieldorder)
rptas_val(K) = rptas.(fieldorder{K});
end

Sign in to answer this question.

Products


Release

R2018b