MATLAB: Assigning values to an array using elements of another array after each element goes through a check

arrayarraysassigncheckdimensionselementifnewvalue

Hello,
Let's say that i have an array (e.g zeros(5,5)).
I'd like to use each element my array has, put each element through an if statement check, make some calculations, and assign that new value to another array that has the same dimensions as my initial one.
If anybody has any idea i'd be of great help!
Thanks!:)

Best Answer

I think your looking for something like this
start_matrix = rand(5,5); %rand 5x5, values between 0 and 1 (cause whats the point in comparing zeros)
end_matrix = zeros(size(start_matrix)); %same size as starting matrix
for i = 1:size(start_matrix,1)
for j = 1:size(start_matrix,2)
if (start_matrix(i,j) > 0.5)
end_matrix(i,j) = start_matrix(i,j) * 666; %some crazy calculations
else
end_matrix(i,j) = start_matrix(i,j); %no crazy calculations if <= 0.5
end
end
end
end_matrix