make calculations with excel file data
Show older comments
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 Comments
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
on 10 Sep 2015
Accepted Answer
More Answers (1)
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 Comments
Joaquim Monteiro
on 25 Sep 2015
Hmmm....does it stay bounded over the array length?
>> p=pc(1);
for i=1:8760
p=p*975;
if (realmax/p)<975,break,end
end
fprintf('%d %e\n',i, p)
102 6.691326e+307
>>
So, assuming the rest of the data are similar to those provided, 975 is roughly the average of the first half-dozen or so values and hence is the ratio of pc(N+1)/pc(N) and so the estimate of how large a value you can compute is given by the above at only a few over 100 observations.
Methinks, somehow, this can't be correct, whatever it is.
Joaquim Monteiro
on 26 Sep 2015
dpb
on 26 Sep 2015
OK, just so's you recognize the issue...
Categories
Find more on String Parsing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!