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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by