How can i iteratively reduce the value of particular matrix elements?
Show older comments
I have a matrix called "weighted_cost" that is created by multiplying two other matrices of the same size, "weighted_C" and "weighted_B". I want to select 4000 random elements from "weighted_cost", and find their indices. Then I want to subtract .05 from all of these elements in another matrix "C", which is the same size as "weighted_cost", if they meet certain conditions. The elements must not have negative values and I try to implement this in the code below. This all should happen 336 times. I do not receive any errors when I run the code, however, upon checking if the original matrix "C" is different from the resulting matrix "C2", I find that they are exactly the same. If the code "works", some cells in matrix "C2" should have much lower values than "C". Can anyone please let me know if anything seems wrong with the code below?
[C,R3]=arcgridread('march_evi_s1_projected.txt');
for t=1:336; %1ST FOR
C2=C
weighted_C=C2.*.4;
weighted_B=B.*.6;
weighted_cost=weighted_C.*weighted_B ;
if any(weighted_cost)<=0
weighted_cost(weighted_cost<0)=0
end
random_patches=weighted_cost(randperm(numel(weighted_cost),4000));
[L1,random_patches_indexes]=ismember(random_patches,weighted_cost);
%Here we are subtracting a certain .05 the EVI of the random cells
if C2(random_patches_indexes)<=0;
C2(random_patches_indexes)=0;
else C2(random_patches_indexes)~=0 & (C2(random_patches_indexes)-.05>0);
C2(random_patches_indexes)-.05;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!