- It is dangerous to use FIND without checking whether the output is empty or non-scalar.
- If you have the image processing toolbox, most of your code, which is just a minimization filter, could be replaced by the single line
Matlab function won't return matrices as outputs?
7 ビュー (過去 30 日間)
古いコメントを表示
I created a function that should return two matrices [roffset, coffset] as outputs, but when I run the function I receive two nx1 vectors. Though, the code works when I copy and paste it into the command window. Why won't it work through the function?
Here's the function:
function [roffset, coffset] = findLowNhbr(map)
r = 1;
c = 1;
% outer loop, going through the rows of the matrix
while c <= size(map,2)
% inner loop, going through the columns of the matrix
while r <= size(map,1)
if r == 1 || c == 1
roffset(r,c) = 0;
coffset(r,c) = 0;
elseif r == size(map,1) || c == size(map,2)
roffset(r,c) = 0;
coffset(r,c) = 0;
else
% determines the offsets
pr = -1:1; pc = -1:1;
% creates a matrix of map(r,c) and its surrounding elements
P = map(r + pr, c + pc);
[or, oc] = find(P == min(P(:)));
roffset(r,c) = or - 2;
coffset(r,c) = oc - 2;
end
r = r + 1;
end
c = c + 1;
r = 1;
end
0 件のコメント
回答 (1 件)
Matt J
2013 年 4 月 16 日
編集済み: Matt J
2013 年 4 月 16 日
Possibly because you're passing an nx1 matrix "map" as input. We can't really know what's going on without you specifying how to reproduce what you're seeing. Two remarks, though
imerode(map, ones(3))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!