Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
need to modify some values in a multidimensional array

Subject: need to modify some values in a multidimensional array

From: Kirk

Date: 1 Jul, 2011 15:46:10

Message: 1 of 3

I am using mvnrnd() to create random climate in a multidimensional array. However, some of the values are nonsensical (such as precipitation values less than zero. To correct this problem, I tried to use an if statement to identify and replace negative precipitation values with 0.

Here is the code which inserts the output of mvnrnd into the final 200 years of monthly climate rows, for columns 3 through 6, for all arrays i. Precipitation is in column 6.

for i = 1:n;

    climate(12001:14400,3:6,i) = mvnrnd(muPost,sigmaPost);
    
end;

if climate(:,6,:) < 0
    climate(:,6,:) = 0;
end

Obviously my if statement is not doing what I think it should. Any suggestions would be appreciated. Thanks in advance.

Subject: need to modify some values in a multidimensional array

From: Jeff

Date: 1 Jul, 2011 18:20:26

Message: 2 of 3

"Kirk" <kwythers.nospam@umn.edu> wrote in message <iukq42$o5b$1@newscl01ah.mathworks.com>...
> I am using mvnrnd() to create random climate in a multidimensional array. However, some of the values are nonsensical (such as precipitation values less than zero. To correct this problem, I tried to use an if statement to identify and replace negative precipitation values with 0.
>
> Here is the code which inserts the output of mvnrnd into the final 200 years of monthly climate rows, for columns 3 through 6, for all arrays i. Precipitation is in column 6.
>
> for i = 1:n;
>
> climate(12001:14400,3:6,i) = mvnrnd(muPost,sigmaPost);
>
> end;
>
> if climate(:,6,:) < 0
> climate(:,6,:) = 0;
> end
>
> Obviously my if statement is not doing what I think it should. Any suggestions would be appreciated. Thanks in advance.

Without an example of your input data I can't guarantee this will be applicable to your situation, but here is a simple example that accomplishes something similar using randomized data:
input = random('normal', 0, 1, 4,4);
input (:,:, 2) = random('normal', 0,2, 4,4);
idx = input(:,:,1) <0;
output = input(:,:,1);
output(idx) = 0;
input(:,:,1) = output;

Subject: need to modify some values in a multidimensional array

From: dpb

Date: 1 Jul, 2011 18:26:03

Message: 3 of 3

Kirk wrote:

...


> use an if statement to identify and replace negative precipitation
> values with 0.
...


> if climate(:,6,:) < 0
> climate(:,6,:) = 0;
> end
...


climate(climate(:,6,:) == 0) = 0;

--

Tags for this Thread

No tags are associated with this thread.

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.

Contact us