How can I use excel file values to make matlab calculations

2 ビュー (過去 30 日間)
Joaquim Monteiro
Joaquim Monteiro 2015 年 7 月 21 日
コメント済み: Joaquim Monteiro 2015 年 7 月 22 日
I'm a newbie in matlab, so can anyone help me in the following question?
I want to use the data of a excel file in a matlab script.
I already import data with the following code (weather data file):
[fileName,pathname] = uigetfile({'*.xlsx'},'Select Location'); nomeficheiro=strcat(pathname,fileName); [a,b,c]=xlsread(nomeficheiro, 'A2:AJ8762'); location = c (1,2); set(handles.location_text,'String',location); In this example I get the location of the weather data using the value store in row 1 and column 2.
In this file in the column 8, we have 8760 hourly values of ambient temperature.
I need to do a calculation with all the values.
For example, import value row 1 and column 8, make calculation in matlab script, next import value row 2 and column 8, make calculation in matlab script, next import value row 3 and column 8, make calculation in matlab script,... and so on....
Thanks

採用された回答

Grant
Grant 2015 年 7 月 21 日
The xlsread "raw" return value (your "c" matrix) is a cell matrix.
A cell matrix is essentially a matrix of matrices, where your string values in the excel will be 1xN character arrays, numerical values will be 1x1 double arrays, and empty cells will be a 1x1 NaN.
Spreadsheet programs will sometimes format cells containing numeric data as strings (or string is the default cell format and never changed), so you may need to use the str2num or str2double functions to perform numerical calculations.
You can index cell matrices in two ways. c(:,8) will return a Nx1 cell array, whereas c{:,8} will return N*1 values that are the contents of the embedded matrices.
You can use the function cellfun to execute a function on each cell contents. In your case, if you have a function F to process a data point, you might use the syntax
results = cellfun(@F,c(:,8))
or
results = cellfun(@(x)F(str2double(x)),c(:,8))
Where "@(x)F(str2double(x))" is an anonymous function (think lambda notation) that calls F after converting the input from a string to a double. If your result is numeric, cellfun can return a Nx1 double. If your results are not uniform, you can add the arguments "cellfun(@F,c(:,8),'Un',false)" and cellfun will return an Nx1 cell array.
You can write these values back into a spreadsheet using xlswrite.
  1 件のコメント
Joaquim Monteiro
Joaquim Monteiro 2015 年 7 月 22 日
Hi Grant,
Thanks for your answer.
Maybe is a stupid questions, but like I said earlier I'm a "very" newbie in matlab (working just at 2 weeks). In my example, I don't know how to automate the calcultation. For example:
row 1 - column 8 - value=5.6, need to calculate Te = value * 2,7; row 2 - column 8 - value=5.9, need to calculate Te = value * 2,7; .... Then I want to sum the first 744 Te values corresponding to the month of January and put like Tejan = sum of 744 first values. Then do the same thing to February ... ....
Can you help me to do this?
Thank in advance

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by