Different variable type when using function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Réponses (1)
Walter Roberson
le 17 Déc 2016
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 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!