Different variable type when using function
조회 수: 1 (최근 30일)
이전 댓글 표시
I thought I managed to make everything working decently but after searching for any error one thousand times, I found one in one of my functions.
So, I have this function:
function [path, amountofpaths, dist_parc] = caminhos(origem, prev, valores_adj_final)
clc;
amountofpaths = length(prev);
path = cell(1, amountofpaths);
dist_parc = cell(1,amountofpaths);
for i = 1:amountofpaths
if ~(origem == i)
a = prev(i);
path{i}(1) = i;
b=2;
while a ~= 0
path{i}(b) = a;
a = prev(a);
b = b+1;
end
end
end
for i = 1:amountofpaths
path{i} = flip(path{i});
end
for i = 1:amountofpaths
if length(path{i}) == 2
for j = 1
dist_parc{i} = valores_adj_final(path{i}(j), path{i}(j+1));
end
end
if length(path{i}) > 2
for j = 1:length(path{i})-1
dist_parc{i}(j) = valores_adj_final(path{i}(j), path{i}(j+1));
end
end
end
end
The variable dist_parc should be a cell, if I run this as a script ( with the same variable values), it is. If I run the function it ends up being a double. Any idea why?
답변 (1개)
Walter Roberson
2016년 12월 17일
Do not use path as a variable name, as MATLAB might misinterpret it as the key variable path that MATLAB uses to figure out what functions are available to be called.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!