make calculations with excel file data
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joaquim Monteiro
el 9 de Sept. de 2015
Comentada: dpb
el 26 de Sept. de 2015
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 comentarios
dpb
el 9 de Sept. de 2015
Editada: dpb
el 10 de Sept. de 2015
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...
Respuesta aceptada
dpb
el 10 de Sept. de 2015
"_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 comentarios
Más respuestas (1)
dpb
el 24 de Sept. de 2015
Editada: dpb
el 24 de Sept. de 2015
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 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!