Remove some elements from a matrix but conserve the same struct
显示 更早的评论
i have the matrix
x=[0 -1 0 5 10 5 0 0;
0 0 5 10 20 10 5 0;
1 -1 0 5 10 5 2 0;
0 2 1 0 5 2 1 0;
0 0 0 -10 0 0 0 0;]
i would like to "disappear" the values between -1 and 5 and keep the matrix with same struct but only the wanted values. the new matrix going to be something like this:
x=
[ 10 ;
10 20 10 ;
10 ;
;
-10 ;]
采纳的回答
更多回答(2 个)
Sean de Wolski
2011-3-29
Rafael, then set everything in the range you described to NaN, and mesh will pretend they're not there.
X(X>=-1&X<=5) = nan;
mesh(X);
You can reduce the size of the matrix first by zeroing out any rows/columns that contain no "peaks". Use the ANY function and the dimensional option to do this.
3 个评论
Rafael Freire
2011-3-29
Matt Fig
2011-3-29
+1 Sean!
@ Rafael I hope next time you will include the "why" when asking about the "how!" ;-)
Rafael Freire
2011-3-29
Sean de Wolski
2011-3-29
x2 = cellfun(@(x)x(x>5|x<-1),num2cell(x,2),'uni',false)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!