How do I generate executable code from imported data?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Johannes
am 27 Nov. 2023
Kommentiert: Dyuman Joshi
am 29 Nov. 2023
I have an xlsx file with various data for the calculation I'd like to conduct with my Matlab code. This file also contains the relevant formulas. Is there a way to import those formulas from xlsx (having them as a string) and convert them to normal code thats executable?
5 Kommentare
Dyuman Joshi
am 27 Nov. 2023
Sorry, I was away from my PC due to some other work. Please check my answer below.
Akzeptierte Antwort
Dyuman Joshi
am 27 Nov. 2023
You need to add the @(list_of_independent_variables) before the formulae.
Flushmatrix = readtable('Spülmatrix2.xlsx','PreserveVariableNames',true)
%values for variables
psat = 1.5;
p_fmin = psat+1;
v = 330;
%Value from the formula copied and pasted
((table2array(Flushmatrix(1,3))*(v/1000)+table2array(Flushmatrix(1,4)))*log(psat)+(table2array(Flushmatrix(1,5))*v+table2array(Flushmatrix(1,6))))/1000
%formula from the table read
a = Flushmatrix(1,9);
a = string(table2cell(a))
%convert the string to a function handle
fh = str2func(a)
%corresponding value
fh(Flushmatrix, v, psat)
3 Kommentare
Dyuman Joshi
am 29 Nov. 2023
I see.
Also, you can modify this lines -
a = Flushmatrix(1,9);
a = string(table2cell(a));
fh = str2func(a);
to
fh = str2func(Flushmatrix{1,9})
For more info - Access Data in Tables
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!