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!