필터 지우기
필터 지우기

I am getting a CELL2MAT error and dont know why.

조회 수: 2 (최근 30일)
badscience
badscience 2019년 3월 13일
댓글: Walter Roberson 2019년 3월 14일
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