Is there a way to convert from Excel data to code conversion?

9 views (last 30 days)
Hi,
I have excel data implemented with formulas and i want to implement the same data in matlab. Is there a way to import the code directly instead of writing line by line?
Example excel data:
Column1= 1:10
column2 = 2:11
column3= Column1^3+Colum2^2
Column4=root(Column1)+Colum2^5
Column5= If(Colum3>Column4)
Output = 1 else Output = 0
Like this i have lot of columns with different kinds of formulas.
Is there any tool in matlab to get all the formulas directly from excel to matlab code?
Thanks in advance
  3 Comments
Haritha
Haritha on 1 Apr 2019
Edited: per isakson on 1 Apr 2019
IFERRROR(+VLOOOKUP(A2,'File directory[Filename.xlsx]Lookup'!$A$1:N18,2,FALSE),"")
If any one knows how to implement this formula in matlab

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 1 Apr 2019
Edited: Adam Danz on 1 Apr 2019
If any one knows how to implement this formula in matlab
IFERRROR(+VLOOOKUP(A2,'File directory[Filename.xlsx]Lookup'!$A$1:N18, 2, FALSE),"")
% [1] |----------------------[2]-------------------|[3] [4]
This vlookup function searches the first column of the dynamically produced table [2] for the value stored in A2 [1] and returns the value stored in the 2nd column [3] of that row. The 'false' flag [4] requires an exact match.
The first step is to get the data from "'File directory[Filename.xlsx]Lookup'!$A$1:N18" and put it into a matrix. I assume this has already been done *(see comment below).
Below is the vlookup function in matlab and a demo.
% Create vlookup equation that looks for value 'v' in column 1 of matrix 'd'
% and returns the corresponding value in column 'c'.
vlookup = @(v,d,c) d(d(:,1)==v,c);
% Produce fake data
data = magic(5)
% look up value 36 in column 1 of 'data' and
% return corresponding value in column 3
vlookup(10, data, 3)
It returns an empty value which is the same thing your excel line is designed to do.
  1 Comment
Adam Danz
Adam Danz on 1 Apr 2019
Edited: Adam Danz on 2 Apr 2019
(*) judging by that single line of code and the dynamically defined table (matrix), I have a feeling a large part of your project will be to load the data into matlab and organize it. Take your time with this. Data cleaning is often 80% of the job.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!