How to write a table in a textarea on a Matlab App?
Mostra commenti meno recenti
Hello all,
I am creating a Matlab App to perform some calculations, the calculation results are included in a table, and it includes numbers and text. I need to write the content of that table in a textarea so that the user can see the results after the calculation finishes. I am currently using the "compose" function, but I get a message error saying that "conversion to double from table is not possible".
Below are the three rows in the code:
formatSpec='%.0f;%s;%.0f;%s;%.2f;%.2f;%.2f;%.f2;%.2f';
Out_Zsc = table(Out_Zsc_Dou(:,1,cas),Out_Zsc_Str(:,1,cas),Out_Zsc_Dou(:,2,cas),Out_Zsc_Str(:,2,cas),Out_Zsc_Dou(:,3,cas),Out_Zsc_Dou(:,4,cas),Out_Zsc_Dou(:,5,cas),Out_Zsc_Dou(:,6,cas),Out_Zsc_Dou(:,7,cas),'VariableNames',{'Coil','Winding','Active Turn','Conductor', 'Power (MVA)', 'Voltage (kV)','Current (A)', 'Amp-Turn (A)', 'Acc. Amp-Turn (A/mm)'})
app.Zsc.Value=compose(formatSpec,Out_Zsc);
I am struggling to find the solution, I wonder if maybe the issues is the variables names which is included above the table. If I print the table in the command window, it works well:
Coil Winding Active Turn Conductor Power (MVA) Voltage (kV) Current (A) Amp-Turn (A) Acc. Amp-Turn (A/mm)
__________ _______ ___________ _________ ___________ ____________ ___________ ____________ ____________________
1.0000e+00 "LV" 5.0000e+00 "LV" 2.3750e+02 2.5000e+01 9.5000e+03 4.7500e+04 -6.4189e+01
2.0000e+00 "LV" 5.0000e+00 "LV" 2.3750e+02 2.5000e+01 9.5000e+03 4.7500e+04 -1.2838e+02
3.0000e+00 "HV" 2.6000e+01 "HN" 2.3750e+02 2.2047e+02 1.0772e+03 2.8008e+04 -9.0529e+01
4.0000e+00 "HV" 2.5000e+01 "HN" 2.3750e+02 2.2047e+02 1.0772e+03 2.6931e+04 -5.4136e+01
5.0000e+00 "HV" 2.4000e+01 "HN" 2.3750e+02 2.2047e+02 1.0772e+03 2.5854e+04 -1.9198e+01
6.0000e+00 "HV" 2.3000e+01 "HN" 2.3750e+02 2.2047e+02 1.0772e+03 2.4777e+04 1.4284e+01
7.0000e+00 "HV" 2.1000e+01 "HL" 2.3750e+02 2.2047e+02 1.0772e+03 2.2622e+04 4.4855e+01
8.0000e+00 "HV" 2.0000e+01 "HL" 2.3750e+02 2.2047e+02 1.0772e+03 2.1545e+04 7.3969e+01
9.0000e+00 "HV" 1.9000e+01 "HL" 2.3750e+02 2.2047e+02 1.0772e+03 2.0468e+04 1.0163e+02
1.0000e+01 "HV" 1.8000e+01 "HL" 2.3750e+02 2.2047e+02 1.0772e+03 1.9390e+04 1.2783e+02
1.1000e+01 "LV" 5.0000e+00 "LV" 2.3750e+02 2.5000e+01 9.5000e+03 4.7500e+04 6.3643e+01
1.2000e+01 "LV" 5.0000e+00 "LV" 2.3750e+02 2.5000e+01 9.5000e+03 4.7500e+04 -5.4652e-01
Any idea what I am doing wrong? any other method to write this table in the textarea? thanks.
Risposta accettata
Più risposte (1)
Walter Roberson
il 5 Feb 2025
app.Zsc.Value(cas)=compose(formatSpec,Out_Zsc(cas));
First off, your code Out_Zsc(cas) is an attempt to subscript at table with a single index. Subscripting a table with a single index is not permitted. If cas is row indices, then you would need Out_Zsc(cas,:). It seems unlikely, however, that cas is row indices, as you are using cas to select pages out of multidimensional data.
Next... your format specification to compose() is a character vector. The output of compose() with a character vector format, is a cell array of character vectors. You are assigning that cell array of character vectors to app.Zsc.Value(cas) which is probably not a cell array, and is probably the wrong size.
But your basic problem is that compose() cannot work with table() parameters.
You have two choices:
- either convert the table to string array by using Out_Zsc{:,:} -- OR
- pass compose the individual table columns
compose(formatSpec, Out_Zsc.Coil, Out_Zsc.Winding, Out_Zsc.('Active Turn'), Out_Zsc.Conductor, Out_Zsc.('Power (MVA)'), Out_Zsc.('Voltage (kV)'), Out_Zsc.('Current (A)'), Out_Zsc.('Amp-Turn (A)'), Out_Zsc.('Acc. Amp-Turn (A/mm)'))
1 Commento
Pablo
il 5 Feb 2025
Categorie
Scopri di più su JSON Format in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!