How to import variable names array from Excel as symbolic variables?
Mostrar comentarios más antiguos
I have defined some symbolic variables, let's say by following means:
%%Declaration of all possible symbolic variables based on total number of streams
n_stream = 38; % total no. of streams in the flowsheet
for k=1:n_stream
syms(sprintf('Qs%d', k)) % Solid flow rate
syms(sprintf('Ql%d', k)) % Liquid flow rate
syms(sprintf('Cw%d', k)) % Solid weight fraction in flow
syms(sprintf('CsV%d', k)) % Solid V content
syms(sprintf('ClV%d', k)) % Liquid V content
syms(sprintf('CsZn%d', k)) % Solid Zn content
syms(sprintf('ClZn%d', k)) % Liquid Zn content
end
Now, I want to give the initial value of these variables for an optimization problem. So, what I need to provide are name of variables ordered in a array and a vector of its initial values. They are written in excel file in something like below manner:

What I want to is to report the variable names and its initial values as two different vectors. I am able to successfully import the initial values from excel file by xlsread command. However, I have tried importing the variable names by the different way but it results in cell values instead of symbolic variable names, something like below:
[num txt raw] = xlsread('../../NALCOProjectExcelDoNotRelocate','Sheet1')
txt =
'Qs1'
'Qs14'
'Qs16'
'Qs30'
'Qs33'
'Qs37'
'Ql3'
'Ql4'
'Ql8'
'Ql9'
'Ql11'
'Ql17'
'Ql20'
'Ql28'
'Ql29'
'Ql32'
'Ql35'
'Cw7'
'Cw12'
'Cw13'
'Cw14'
'Cw15'
'Cw16'
'Cw18'
'Cw26'
'Cw31'
'Cw33'
Similar, results for raw type as well.
Also, tried file reading and then writing the code in txt file format. But it gives writing errors, something like below:
[numData textData rawData] = xlsread('../../NALCOProjectExcelDoNotRelocate','Sheet1')
save('pqfile.m', 'rawData', '-ASCII')
new_file = 'pqfile.m'
eval(new_file)
Error:
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'rawData' not written to file.
What I understood from reading over internet that this way I can only write numeric data.
Please help me in troubling the problem. Simply saying, I have defined symbolic variables and want to import the vector of this variable names from excel file.
Thanks in advance and regards...
1 comentario
Stephen23
el 5 de Ag. de 2018
Do you really need symbolic variables? It would be quite easy and efficient to import that data and convert it into a structure of numeric values, which you could thus access simply:
S.QS1
S.QS14
...etc
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!