make calculations with excel file data

10 次查看(过去 30 天)
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....
I want to automate this calculation
I want to store the results of the calculations in textbox in gui.
Thanks
  2 个评论
dpb
dpb 2015-9-9
编辑:dpb 2015-9-10
All the numeric data are in the numeric array a; in Matlab one generally tries to write code to make use of the fact that it can handle full arrays at a time.
What are the calculations you wish to perform on the data in column 8? If it is the same for each, then it will be quite simple; if there's something different for various ones, you'll have to have a way to know which and what do do for each...
Joaquim Monteiro
Joaquim Monteiro 2015-9-10
Is the same calculation for all. This is hourly data (8760 values) of a year. I've to do the calculation, then store the result and then go to the next row of the column 8.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2015-9-10
"_Is the same calculation for all...of the column 8."_
Tf=a(:,8)*1.8+32; % convert column 8 (assume T in C) to F
Done for the whole year in one swell foop...that's the power of Matlab; no loops needed most of the time and are to be avoided when not.
Above gives you a new variable; if you don't need to keep the original but want to overwrite, then simply
a(:,8)=a(:,8)*1.8+32; % convert column 8 (assume T in C) to F
Since you still haven't made us privy to the actual calculation, I just made up an example; simply replace the specific with whatever yours is.
  19 个评论
Joaquim Monteiro
Joaquim Monteiro 2015-9-23
编辑:dpb 2015-9-24
There's the data.
10 2011 1 1 10 60 ... 7 3.8 80 100201 409 1413 301 251 625 69 32803 78625 9914
11 2011 1 1 11 60 ... 8.3 4.1 75 100201 536 1413 319 356 697 90 46892 89034 12932
12 2011 1 1 12 60 ... 9.5 4.5 71 100201 602 1413 325 416 736 101 55111 94819 14512
13 2011 1 1 13 60 ... 10.3 4.7 68 100201 602 1413 329 416 736 101 55111 94819 14512
14 2011 1 1 14 60 ... 10.6 4.7 67 100201 536 1413 330 356 697 90 46892 89034 12932
I want to do
Pc1 = value column8 + 253,2 + column16
This result is use as a input to the 2nd row
Pc2 = Pc1*((value column8 + 253,2 + column16 )-(value column20)
Pc3 = Pc2*((value column8 + 253,2 + column16 )-(value column20)
Joaquim Monteiro
Joaquim Monteiro 2015-9-24
PORTO =
1.0e+05 *
Columns 1 through 12
0.0001 0.0201 0.0000 0.0000 0.0001 0.0006 NaN 0.0001 0.0000 0.0008 1.0020 0.0041
0.0001 0.0201 0.0000 0.0000 0.0001 0.0006 NaN 0.0001 0.0000 0.0008 1.0020 0.0054
0.0001 0.0201 0.0000 0.0000 0.0001 0.0006 NaN 0.0001 0.0000 0.0007 1.0020 0.0060
0.0001 0.0201 0.0000 0.0000 0.0001 0.0006 NaN 0.0001 0.0000 0.0007 1.0020 0.0060
Columns 13 through 20
0.0141 0.0030 0.0025 0.0063 0.0007 0.3280 0.7863 0.0991
0.0141 0.0032 0.0036 0.0070 0.0009 0.4689 0.8903 0.1293
0.0141 0.0032 0.0042 0.0074 0.0010 0.5511 0.9482 0.1451
0.0141 0.0033 0.0042 0.0074 0.0010 0.5511 0.9482 0.1451
>> Pc1=PORTO(1,8)+253.2+PORTO(1,16)
Pc1 =
885.2000
>> Pc2=Pc1*(PORTO(2,8)+253.2+PORTO(2,16))-PORTO(2,20)
Pc2 =
8.3553e+05
>> Pc3=Pc2*(PORTO(3,8)+253.2+PORTO(3,16))-PORTO(3,20)
Pc3 =
8.3443e+08
and so on until Pc8760

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2015-9-24
编辑:dpb 2015-9-24
OK, that's one interpretation but seems unlikely that that's what you really, really intend...that's going to "blow up" to an extremely large number in the end...
But, for the above as written simplest coding is in a loop although there are ways to vectorize it, will leave those for more advanced lesson particularly as I don't expect you're going to like the result as it will overflow in all likelihood by the time you reach the end...
>> pc=d(:,8)+253.2+d(:,16);
>> for i=2:length(pc),pc(i)=pc(i-1).*pc(i)-d(i,20),end
pc =
1.0e+05 *
0.0089
8.3553
0.0100
0.0100
0.0096
pc =
1.0e+08 *
0.0000
0.0084
8.3443
0.0000
0.0000
pc =
1.0e+11 *
0.0000
0.0000
0.0083
8.3401
0.0000
pc =
1.0e+14 *
0.0000
0.0000
0.0000
0.0083
8.0132
>>
Above shows the same results as your calculation with the entry of each loop in range of the display each iteration.
I don't understand what it is you're actually physically trying to compute so can't judge the appropriateness of the formulation for the purpose. BUT, note that pc(1) has units of whatever d(8) and d(20) are but you've then squared that value and added another term in only units(d). Unless these are dimensionless, that's clearly in error for a physical system computation.
  4 个评论
Joaquim Monteiro
Joaquim Monteiro 2015-9-26
Dpb, you are right, the modelling that i need at this moment are not complete, but is sufficient for now to move forward.
dpb
dpb 2015-9-26
OK, just so's you recognize the issue...

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by