Thread Subject: a simple control flow to find the index and replace

Subject: a simple control flow to find the index and replace

From: Kuo-Hsien

Date: 25 Feb, 2009 14:50:04

Message: 1 of 5

Dear all,

Here is my code to supplement missing data in the specific time based on the index.

Can you advice me or provide me some hints how to write the part of control flow? I already try several way, but I need to pick up some clues.

Thanks so much.
Michael

load ('data_A_2007');
load ('data_B_2007');
load ('data_C_2007');

year = 2007;
doy=yeardays(year);
[L W] = size(year);

if L < W;
year = year';
[L W] = size(year);
end

ind = [1:1:L]';

start_time = datenum(year(ind(1)), 1, 1) + step/1440;
end_time = datenum(year(ind(L))+1, 1, 1);

time_vector = [start_time : step/1440 : end_time]';
base_vector = floor(time_vector(1,:));
day_vector = time_vector - base_vector - doy;

% summer time : doy >=91 and <=275; night time hour: 6 - 19
% winter time : doy <90 and >275; night time hour: 7 - 18

for day_vector(1:90*24*2 & 275*24*2:end)
night_index = find(floor(day_vector)< 7/24 | floor(day_vector)> 18/24);
else
night_index = find(floor(day_vector)< 6/24 | floor(day_vector)> 19/24);
end

night_missingdata_index = find(data_A_2007(night_index) & isnan(data_B_2007));
data_A_2007(night_missingdata_index) = data_C_2007(night_missingdata_index);

Subject: a simple control flow to find the index and replace

From: Kuo-Hsien

Date: 26 Feb, 2009 13:27:02

Message: 2 of 5

Hi all, are there any suggestions and tips for this post? Thank so much. Michael

Subject: a simple control flow to find the index and replace

From: us

Date: 26 Feb, 2009 13:38:01

Message: 3 of 5

"Kuo-Hsien"
> Hi all, are there any suggestions and tips for this post...

you need to curtail your (tedious) idiosyncratic snippet (including files that are not accessible to CSSMers) to the very (bare bone) problem - in easily copy/pasteable code - you want this NG to look at...

us

Subject: a simple control flow to find the index and replace

From: Kuo-Hsien

Date: 27 Feb, 2009 07:39:01

Message: 4 of 5

Thanks for your helps. I should make it more clearer and readable.

Here is my two problems:
(1) how to do some judgement based on a specific range of index?
(2) how to approach my purpose by utilizing if ... end or while ... end?

For example, I create a series of index<8760x1 double>, I like to sort out the index based on the conditions: (a) location from 1 to 1000, 8000 to the end and the rest; (b) the decimal value from 0 to 0.3, 0.7 to 1 and the rest.

index = repmat((0:1/24:0.9584)',[365 1]);
value = rand(1,8760)';

if index(1:1000 & 8000:end)
index_tail=find(floor(index)<0.3 | floor(index)>0.7)
else
index_mid=find(floor(index)>=0.3 | floor(index)<=0.7)
if index(1001:7999)
index_tail=find(floor(index)<0.3 | floor(index)>0.7)
else
index_mid=find(floor(index)>=0.3 | floor(index)<=0.7)
end
index_final = find((index_tail) & value>0.8);

Please advice me how to correct my code. If I did not make my question clear or misunderstand the logics, please feel free to let me know. Thanks for your advices.

Michael

Subject: a simple control flow to find the index and replace

From: Kuo-Hsien

Date: 27 Feb, 2009 07:41:03

Message: 5 of 5

Thanks for your helps. I should make it more clearer and readable.

Here is my two problems:
(1) how to do some judgement based on a specific range of index?
(2) how to approach my purpose by utilizing if ... end or while ... end?

For example, I create a series of index<8760x1 double>, I like to sort out the index based on the conditions: (a) location from 1 to 1000, 8000 to the end and the rest; (b) the decimal value from 0 to 0.3, 0.7 to 1 and the rest.

index = repmat((0:1/24:0.9584)',[365 1]);
value = rand(1,8760)';

if index(1:1000 & 8000:end)
index_tail=find(floor(index)<0.3 | floor(index)>0.7)
else
index_mid=find(floor(index)>=0.3 | floor(index)<=0.7)
if index(1001:7999)
index_tail=find(floor(index)<0.3 | floor(index)>0.7)
else
index_mid=find(floor(index)>=0.3 | floor(index)<=0.7)
end
index_final = find((index_tail) & value>0.8);

Please advice me how to correct my code. If I did not make my question clear or misunderstand the logics, please feel free to let me know. Thanks for your advices.

Michael

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
if else Kuo-Hsien 3 Mar, 2009 15:20:58
scolding us 26 Feb, 2009 08:40:23
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com