A quick xlsread, xlrwrite question - Multiple Cell Reference Input

1 view (last 30 days)
Hello, I have a small inquiry about xls functions. I have a Excel file with 41 station coordinates.
Column A has Station name (Name in function: Station)
Column B has Station Latitude (Name in function: Lat)
Column C has Station Longitude (Name in function: Lon)
QUESTION 1: Each of those above 3 data will be my input for further functions and I want to create a loop to automate my main function for all 41 stations.
As an example; at i=1, first station name and position being operated in the loop will be (A1, B1, C1)
for i=2; A2, B2, C2 ..... for i=41; A41, B41, C41
I want to create a dynamic xlsread function to achieve multiple cell reference input.
*QUESTION 2:*I will list the results of the main function to a excel file with the above station name mentioned being the Sheet name. I tried some known notations inside the xlswrite function but couldnt do it.
Here is my code for guidance:
function PixValue
for j=1:41
%XLSREAD FUNCTIONS WILL BE TYPED HERE
Filename = dir('*.grb');
for i=1:length(Filename)
[Data,Info]=readGRIB2(Filename(i).name);
Data=Data.*3600;
Time=strcat(Date2DateStr(Info.Date(1),Info.Date(2),Info.Date(3),Info.Date(4),Info.Date(5)));
[Row,Column] = msgCoord2pix(Lat,Lon);
Product=Data(Row,Column);
A={Time Product};
xlswrite('eventresult.xls',A,SHEETNAME OPERATION WILL BE TYPED HERE,num2str(i));
end
end

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 21 Aug 2011
Do xlsread() once. 41x3 matrix is not large at all. Doing xlsread() 41 times is not in-efficient. [Num,Txt,Raw]=xlsread('YourDataFile.xls') will likely put your lat and lon data into Num, which will be 41x2 array. The Txt variable will contain your 41 station name. At the worse case, all original data will be in the cell array "Raw".
Assume Txt{i} contains the station name, you can write your data to the Excel file with corresponding file name and sheet name.
xlswrite([Txt{i},'.xls'],A,Txt{i})

More Answers (0)

Community Treasure Hunt

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

Start Hunting!