A null assignment can have only one non-colon index
311 views (last 30 days)
Show older comments
Chathurika Jayasundara
on 11 Sep 2018
Commented: Jon Aztiria
on 16 Jun 2021
B=zeros(23,23)
for r=1:23;
for n=1:23;
if r==n
B(r,n)=A(r,n);
else
B(r,n)=[];
end
end
end
A is a symmetric 23*23 matrix and I want to remove all the other values except r=n. It gives me an "A null assignment can have only one non-colon index" error
0 Comments
Accepted Answer
KSSV
on 11 Sep 2018
B=zeros(23,23)
for r=1:23;
for n=1:23;
if r==n
B(r,n)=A(r,n);
else
B(r,n)=NaN;
end
end
end
4 Comments
Declan O'Callaghan
on 30 Nov 2020
I found that using NaN was not the same as removing an element. How do we remove elements?
More Answers (0)
See Also
Categories
Find more on Shifting and Sorting 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!