Hello, I have two nxm matrices A and B and want to create new nxm matrix C which elements are key:value pairs of A and B elements.
Example:
A = [1 2;
3 4];
B = [5 6;
7 8];
C = [{1: 5} {2: 6}
{3: 7} {4: 8}];

댓글 수: 2

Guillaume
Guillaume 2020년 3월 1일
편집: Guillaume 2020년 3월 1일
Can you rewrite your desired C result using valid matlab syntax. {1: ...} is not valid matlab syntax, so it's difficult to understand what result you want. {1, 5}, {[1, 5]}, {'1: 5'} would be valid syntax but it's not clear if it's any of these that you want.
Perhaps, you should explain what you're going to do with the result afterwards.
metrus
metrus 2020년 3월 1일
편집: metrus 2020년 3월 1일
I want to create new matrix, which nth element is pair of A's nth element and B's nth element. For example, if A(1,3) = 5 and B(1, 3) = 42, C(1, 3) would be {5->42} (not the vector [5 42]).
I don't know how it works in MATLAB, but in python there is dictionary for this purpose.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2020년 3월 1일

0 개 추천

I believe the closest MATLAB equivalent to python's dictionary is a map container.

댓글 수: 1

Guillaume
Guillaume 2020년 3월 1일
Yes, matlab's map container and python's dictionary are both implementation of associative arrays.
However, the map in matlab, just like the python dictionary is an unordered container, so I'm confused for the requirement of the output being a 2D matrix, which implies some ordering.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2020년 3월 1일

댓글:

2020년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by