Excel import and operations

2 visualizzazioni (ultimi 30 giorni)
dinesh kumar mohan
dinesh kumar mohan il 21 Set 2019
Risposto: Walter Roberson il 21 Set 2019
Hi Everyone,
I have an excel sheet, in which Column 1 is text(eg: A,B,C..) and column 2 is numbers(1,2,3,...), column 3, 4,5,6, with numbers and text.
How to assign the values of column 1( which is text A,B, C,..) takes the values of numbers in column B. While doing operations further in my Matla with some formulas i need the value of column2(numbers) must be used in place of column 1 text and print the result??
So, that my fuction will use the alphabets and results comes from the column 2 nubers.??
  2 Commenti
Walter Roberson
Walter Roberson il 21 Set 2019
I am having difficulty understanding what you want, but if I understand correctly, your first column contains variable names and your second column contains variable values, and you have some formulas written in terms of the variable names which you want to evaluate with the corresponding variable values used in place of th names?
dinesh kumar mohan
dinesh kumar mohan il 21 Set 2019
Yes.. your right..

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 21 Set 2019
Probably the easiest way to do this is to use the symbolic toolbox. You can construct a struct in which the field name is the name from column 1, and the value is the entry from column 2, and you define a symbolic variable with the same name as column 1. Then you can subs(TheFormula, TheStructOfValues) and the symbolic toolbox will do all of the lookups for you.
This approach has the advantage of not needing to change the formula.
However, I would not say that is the best way.
One better way would involve writing the formulas with the variable names as fields referencing a struct. You would construct a struct in which the field name is the name from column 1, and the value is the entry from column 2, and then you would evaluate the formula in terms of the struct.
Another better way would involve writting the formulas with the variable names looking like indexing into an array, such as M('speed')*M('time') instead of speed*time . Then you would construct a containers.Map with the indices taken from the first column of the excel, and the value taken from the second column.

Più risposte (0)

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by