Different variable type when using function

조회 수: 1 (최근 30일)
Nuno Palma
Nuno Palma 2016년 12월 16일
답변: Walter Roberson 2016년 12월 17일
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
Walter Roberson 2016년 12월 17일
Could you give us some suggested input?

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

답변 (1개)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by