How to define a time period for my code?

Hi Everybody,
I wrote a code to convert the azimuth and elevation angel to latitude and longitude and plot in circle symbol. I had two problems; 1- The column of my time (time1) start from 0-24h(for one day)and I want to read it just the period time 22-10, it means I do not want to read and plot the period time between 10-22. 2- I would like someone look at my code to make me sure it's correct. When I plot different data the figures doesn't much different which is a bit weird. Could you please help me?
Happy New Year to all of you!

6 Comments

Image Analyst
Image Analyst on 29 Dec 2012
Edited: Image Analyst on 29 Dec 2012
You can paste your code in, then put a blank line in front of it, highlight it and click the "{ } Code" icon. This will format it correctly. You don't need to double space your code to get it to show up on different lines, just highlight and click {}Code.
You would make it easier for someone to help you if you uploaded your data file. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Thank you, much more better. I have uploaded two different data files.
Jan
Jan on 29 Dec 2012
Edited: Jan on 29 Dec 2012
@Ara: The additional blank line after each line of code still reduces the readability. Some of the comment lines look strange, while commented code is confusing only in a forum.
I've struggled with "90.-el1" also, because it looks almost like 90.0e-11.
-Jan: Sorry to make it confused. I've changed it and I hope looks more clear. That line are supposed to calculate 90-elevation angel.
@Ara: Much better now! Thanks.
Ara
Ara on 30 Dec 2012
Edited: Ara on 30 Dec 2012
-Jan: You said much better, but I still did not receive any answer. Should I change another thing or just wait? In this code the column"time" give the time in UT and I just want to plot the daytime so I need to remove 10-22h (which are determine as local night-time).But I do not know how? should I define a threshold? To my knowledge, when I set the specific time I faced error. I also start to read the data just for specific data like data1nov=xlsread('1608_1.xls', 'A2753:AF5803'); % read data But this error comes out: ??? Attempted to access no_sat1nov(1); index out of bounds because numel(no_sat1nov)=0.

Sign in to comment.

 Accepted Answer

It is not possible to "not read" data unless the file is binary and the amount of space taken up by the data to be skipped can be exactly calculated.
Excel might be able to handle doing it for .xls files -- but not for .xlsx files as those are too text-oriented.
My working assumption for Excel data of modest size (as yours is) is that Excel will probably end up reading the data anyhow, and that the best you rely on is that if you know exactly which rows you want, Excel will prune back what it returns to MATLAB.
If you do not know ahead of time the exact positions of what you want Excel to read, then if you are using MS Windows, you might be able to use ActiveX to command Excel to select only the rows where a column matches particular criteria.

7 Comments

when calculated the time by Matlab I do not know the exact position since is different for each data but time column start from 0am and then increase to end up with 24. Is there any way to read the file with all columns and then plot for specific time? I mean just filter that column to read just the value between for ex 10<time <22 or just plot time <10 and of course filter the rest to match the size?
data(data(:,1) < 10 | data(:,1) >= 22, :)
Thank you, Walter. You are really helpful. I just have one question which I can not match this code with my code. I put it like this but get error; data_filtered(time(:,4) <= 10 | time(:,4) >= 22, :);
Could you please tell me how can I match with my code?
Your "time" is a column vector, according to your code. So
time_inrange = time <= 10 | time >= 22;
reduced_data = data_filtered(time_inrange, :);
reduced_time = time(time_inrange);
Please re-check the boundary conditions. You wanted to exclude between 10 and 22, but what about 10:00 exactly and 22:00 exactly ? And if there is a minutes field, the current code would include all 10:xx and all 22:xx. You are more likely to want "<" for the 10 rather than "<="
Thank you. Just one more thing, should I have to replace all "data_filtered" in the code by "reduced_time" to calculate the rest in this specific time as well?
No, data_filtered is the data, and reduced_time is a time vector. You might need to use reduced_data instead of data_filtered and use reduced_time instead of time.
Thank you, it works well. Wishing you a great year ahead!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!