How can I query whether a cell is full?

Hi
How can I query whether a cell is full? For example, I want to do something like this using the if structure: if this cell is full, do the action, if not, don't.
thank you for help

8 Comments

Your question is too vague; could you provide an example of what do you mean for "cell"?
what I want to mention is for example : A (1,1)That's what I meant when I said cell.I have matrix that is huge in size and I want to try for all of them.
"Cell" means cell arrays in Matlab. You mean a numerical matrix. Now explain, what "full" means: not zero? Not a NaN?
Got it, thanks for informing. I think it will be more descriptive if I give an example. for example A(10,10 ) might not contain any values. It is completely empty. Or A(9,10)= 10. It says 10 in that series.
I want to query it for a large matrix.
Maybe you could give a small example of a matrix that is "full", and one that is not.
So for example if my A matrix is 2x2
A: 3 4
8 5
A(3,2) array will be empty, right? Or A(2,2)= 5 . What I mean by " full " is that a value is written in A(2,2).
Sorry for not explaining well enough.
It is not possible for an array in MATLAB to have a "hole" (unless the array is a Java array.) So this would be invalid syntax:
A = [1 2; 3] % The second row must have two elements
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
By "full" do you mean that the lower-right corner element of your matrix is non-zero? So [0 0; 0 1] would be "full" but [1 2; 3 0] would not?
Or do you mean that each row and each column has at least one non-zero element, so that the matrix must be at least as large as it is to contain the data? An example of a matrix that is "non-full" by that latter definition is [1 0; 0 0]. The last row and column aren't actually necessary if all you want to do is to store that one non-zero element 1, you can do it with [1].
Part of the confusion, I think, is that "full" in MATLAB usually means "not sparse", i.e. issparse returns false.
Perhaps if you explain how you are planning to use the information about whether a matrix is "full" or not in your program, or what the purpose of your program is, we might be better able to understand how to make that determination (or a way to solve the problem without needing to make that determination.)
If A as an Normal array having size rows=2 & column=2
A=[3 4;8 5]
A = 2×2
3 4 8 5
Here A(3,2) having no sense, as index exceeds matrix dimension. As in matrix there is no empty elements, either it should be numbers or NaN, but it must be.
Hence calling any matrix elements which is out of Matrix dimension have no sense.
On the other hand in cell array which is possible
Lets suppose A is cell array having sizes 2x2
A={2,3;[] 'Kalyan'}
A = 2×2 cell array
{[ 2]} {[ 3]} {0×0 double} {'Kalyan'}
Where
A{2,1} is an empty and other having cell ememnts ('whch you may referring as "Full")
Hope it Helps! :)

Sign in to comment.

Answers (1)

Based on the comments it sounds like you need to use size to check whether the given row and column indices are valid for the given matrix.
A = [3 4; 8 5];
[m,n] = size(A);
rows_to_test = [2 3];
cols_to_test = [2 2];
for kk = 1:numel(rows_to_test)
ii = rows_to_test(kk);
jj = cols_to_test(kk);
% check that indices ii and jj are both valid:
if ii >= 1 && ii <= m && jj >= 1 && jj <= n
result = A(ii,jj);
fprintf('A(%d,%d) = %f',ii,jj,result);
else
result = [];
fprintf('A(%d,%d) does not exist: size(A) = [%d %d]',ii,jj,m,n);
end
end
A(2,2) = 5.000000
A(3,2) does not exist: size(A) = [2 2]

Categories

Tags

Asked:

on 2 Apr 2022

Answered:

on 2 Apr 2022

Community Treasure Hunt

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

Start Hunting!