From: Sal on
Hello,
I have 3 arrays, containing date, distances and ships number. I want to extract (or filter) the information from these arrays for months of august to novembre (inclusive).

I wrote the following code, but it seems really basic and takes abit long. to excute. (~15 seconds)
1. Basically, i wanted to know how to improve it e.g. how could I store the concerned values into new arrays, so that i don't have to filter out the zeros later on, (as i do at the end of the following code.)

2. Is there something else i could use instead of 'while' loop?
3. any other tip/advice would be most appreciated.
Thank you
Salman

Please note: 1. The array days contains dates stored as number of days since 01-01-1900


function [ new_height, new_days, new_ships, = august_november_filter_function( ships, height, days)

tic
[a,s] = size(height);


new_height = zeros(a,s);

new_days = zeros(a,s);

new_ships= zeros(a,s);

while s<=a

[~, months, ~] = datevec( days(s) + datenum(1900,1,1) );

if ((months >=8) && (months <= 11)) % want height values from August to Novembre inclusive


new_days(s) = days(s);

new_ships(s) = ships(s);

new_height(s) = height(s);


else


end

s=s+1;
end


positive_index = find(ddmmyy_days_8_11(:,:)>0); % to filter out the zero-containing indices

new_height = new_height(positive_index);

new_days = new_days(positive_index);

new_ships = new_ships(positive_index);
toc

end
From: us on
"Sal " <salman.hafeez(a)mail.mcgill.ca> wrote in message <i3sss9$k03$1(a)fred.mathworks.com>...
> Hello,
> I have 3 arrays, containing date, distances and ships number. I want to extract (or filter) the information from these arrays for months of august to novembre (inclusive).
>
> I wrote the following code, but it seems really basic and takes abit long. to excute. (~15 seconds)
> 1. Basically, i wanted to know how to improve it e.g. how could I store the concerned values into new arrays, so that i don't have to filter out the zeros later on, (as i do at the end of the following code.)
>
> 2. Is there something else i could use instead of 'while' loop?
> 3. any other tip/advice would be most appreciated.
> Thank you
> Salman
>
> Please note: 1. The array days contains dates stored as number of days since 01-01-1900
>
>
> function [ new_height, new_days, new_ships, = august_november_filter_function( ships, height, days)
>
> tic
> [a,s] = size(height);
>
>
> new_height = zeros(a,s);
>
> new_days = zeros(a,s);
>
> new_ships= zeros(a,s);
>
> while s<=a
>
> [~, months, ~] = datevec( days(s) + datenum(1900,1,1) );
>
> if ((months >=8) && (months <= 11)) % want height values from August to Novembre inclusive
>
>
> new_days(s) = days(s);
>
> new_ships(s) = ships(s);
>
> new_height(s) = height(s);
>
>
> else
>
>
> end
>
> s=s+1;
> end
>
>
> positive_index = find(ddmmyy_days_8_11(:,:)>0); % to filter out the zero-containing indices
>
> new_height = new_height(positive_index);
>
> new_days = new_days(positive_index);
>
> new_ships = new_ships(positive_index);
> toc
>
> end

a hint:
- to look for the bottleneck(s)

help profile;

us