Is there a way to convert from Excel data to code conversion?
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Adam Danz
2019-4-1
编辑:Adam Danz
2019-4-1
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 个评论
Adam Danz
2019-4-1
编辑:Adam Danz
2019-4-2
(*) 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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!