필터 지우기
필터 지우기

how not to be read the cells with zero values.

조회 수: 4 (최근 30일)
fatema saba
fatema saba 2015년 11월 21일
편집: fatema saba 2015년 11월 22일
Hi I have matrix A. This matrix has 1000 rows and 1000 column. many cells of this matrix have 0 as their values.I have to enter this matrix into a loop. this loop starts with:
for i=1:1000
for j=1:1000
....
.....
end
I want in this movement cells that have zero value not to be read. but when I write for i=1:1000 and for j=1:1000 these cells will be read then will be rejected. I hope I can explain my question.
Thank you

답변 (1개)

Image Analyst
Image Analyst 2015년 11월 21일
For example
[rows, columns] = size(A);
for column = 1 : columns
for row = 1 : rows
if A(row, column) ~= 0
% Do something ONLY if the value is not zero.
end
end
end
There are vectorized ways to do things but it depends on exactly what you want to do if the value is non-zero.
  댓글 수: 5
Image Analyst
Image Analyst 2015년 11월 22일
First, let's start using correct terminology. They are not "cells" like Excel calls them - they're "elements". "Cells" are a different beast entirely and I very much recommend you learn about them from the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
What do you want to do? Do you want to compact the array be squeezing it together to get rid of ows and columns from a 3D array where all the elements along the third dimension? You can't arbitrarily remove rows and columns from a 3D array where all the elements along the third dimension. This is because the array must remain rectangular. For example if you were to remove 3 columns from row 1 and 8 columns from row 2, now row 1 and row 2 would not have the same number of columns in them and your array is no longer rectangular - it has a ragged right edge.
fatema saba
fatema saba 2015년 11월 22일
편집: fatema saba 2015년 11월 22일
Thank you for your patient. i know that matrix is rectangular and I can't remove some elements. Actually I don't want remove special elements but I want to decrease these repeats. I Think if I can decrease them by eliminating zero values that are common in all dimensions I can do this. I'm sorry. Thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by