How do I change all the elements in matrix with an index larger than a certain number to zero?
Show older comments
I have trouble making a certain matrix even though it seems trivial. For my code I need to make a 4-D matrix A with dimensions 2x100xmax(K)xP where P=8 and K=round(linspace(1000,2000,P)) . The matrix needs to be all ones, except for K indexes larger than the K that corresponds with the P. For example, A(:,:,:,1) should be all ones except for K's larger than 1000 which should be zeros, and A(:,:,:,8) should be solely ones.
I tried code like
P = 8;
K = round(linspace(1000,2000,P));
A = zeros(2,100,max(K),P);
for i=1:P
A(:,:,:,i) = ones(2,N,K(i));
end
But as my command window showed that is clearly not the way to go.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!