I am getting a CELL2MAT error and dont know why.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am calling a user-defined python function from matlab and it generates two python tuples, P and Q. I need to extract this data for use in MatLab but when I run my code, I get the error:
"Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects."
Here is my code and at the bottom, commented out, is the python module that is being called in MatLab.
runRSK = py.importlib.import_module('RSKAlgPy');
perm = input('Input permutation in the form [a b c ... n]\n');
PQ = runRSK.RSK(perm);
P=PQ(1);
Q=PQ(2);
P1 = cellfun(@(x) cell2mat(cell(x)), cell(P{1}), 'Uniform',false);
P1 = vertcat(P1{:});
Q1 = cellfun(@(x) cell2mat(cell(x)), cell(Q{1}), 'Uniform',false);
Q1 = vertcat(Q1{:});
%% The actual script written in Python
% from bisect import bisect
% def RSK(p):
% '''Given a permutation p, spit out a pair of Young tableaux'''
% P = []; Q = []
% def insert(m, n=0):
% '''Insert m into P, then place n in Q at the same place'''
% for r in range(len(P)):
% if m > P[r][-1]:
% P[r].append(m); Q[r].append(n)
% return
% c = bisect(P[r], m)
% P[r][c],m = m,P[r][c]
% P.append([m])
% Q.append([n])
%
% for i in range(len(p)):
% insert(int(p[i]), i+1)
% return (P,Q)
%
% print(RSK('43512'))
I think maybe the elements of the py.tuples are not the correct types of elements to use cell2mat but I am not sure how to fix this.
3 comentarios
Walter Roberson
el 14 de Mzo. de 2019
if P{1} is a java array, then cell(P{1}) returns a cell array with equivalent content, which is a worthwhile thing to do.
If P{1} happened to be a numeric vector then cell(P{1}) would be asking to preallocate a cell with those sizes, which is not equivalent to just leaving P{1} in the cell.
Respuestas (0)
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!