Need to get dimensions to match and to return a 0 x 0 matrix for empty row.
1 次查看(过去 30 天)
显示 更早的评论
This code give me a 1 x 0 array for any row that is empty. I need it to return a 0 x 0 empty matrix for any row that is empty. It is presently giving me an error and proclaiming that the dimensions of the object in the "if" statement don't match.
function S = logipack( V)
m = size(V, 1);
S = cell(m, 1);
for r = 1:m
S{r} = find(V(r, :));
if find(V(r,:))==[]
S{r}= [];
end
end
end
5 个评论
Jan
2016-12-18
@DJ V: You discus the problem "find(V(r,:))==[]" here, although the answer I've given at https://www.mathworks.com/matlabcentral/answers/317178-what-is-wrong-with-this#answer_247497 contains the correct isempty() already. By this way, you do not catch attraction, but discourage readers to care about your questions.
采纳的回答
John BG
2016-12-16
DJ
MATLAB moans, not because of if condition mismatch, but because the operator '==' doesn't work for cells, try this:
cell1 =
'a' [1] '9' [2x2 double]
>> cell2={'b' 2}
cell2 =
'b' [2]
>> cell1==cell2
Undefined operator '==' for input arguments of type 'cell'.
So,
1.- your 1st line in the for loop doesn't make much sense,
S{r} = find(V(r, :))
so I changed it to
S{r} = V(r, :)
may be it's not what you want but at least now S is not empty.
2.- instead of
if find(V(r,:))=={}
try
if isempty(V(r,:))
or better
if isempty(V(r))
So the following, although not sure whether of much use, at least it doesn't crash
V=randi([-10 10],1,10)
m = size(V, 2);
S = cell(m, 1);
for r = 1:m
S{r} = V(r);
if isempty(V(r))
S{r}= [];
end
end
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
3 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!