I am getting a CELL2MAT error and dont know why.

2 次查看(过去 30 天)
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 个评论
badscience
badscience 2019-3-14
I will give that a shot, sorry I didnt include the data, here is an example of what the code generates so far for an input of [1 5 4 3 2 6]:
P =
Python tuple with no properties.
([[1, 2, 6], [3], [4], [5]],)
whos P
Name Size Bytes Class Attributes
P 1x1 8 py.tuple
Q =
Python tuple with no properties.
([[1, 2, 6], [3], [4], [5]],)
whos Q
Name Size Bytes Class Attributes
Q 1x1 8 py.tuple
The python script runs the RSK algorithm on a given permutation of the symmetric group, i.e. the input is a permutation of some integers 1 through n, and generates two tableaux which are represented by the tuples here. I need to be able to take those tuples and put that data in two separate arrays, one for P, one for Q.
Walter Roberson
Walter Roberson 2019-3-14
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by