필터 지우기
필터 지우기

Access cell array using an indexed array

조회 수: 3 (최근 30일)
Changho Lee
Changho Lee 2018년 3월 16일
답변: vijaya lakshmi 2018년 3월 19일
Hi,
I have a short question.
Suppose that I save some data into a cell array like this,
T{1,1} = [1,2,3];
T{2,1} = [4,5,6];
T{3,1} = [7,8,9];
and I have an index array like this.
idx = [3,2,1];
In this situation, I want to get the result like this.
ans = [3,5,7]
How can I make a code??
Really thanks in advance.

답변 (1개)

vijaya lakshmi
vijaya lakshmi 2018년 3월 19일
Hi Changho,
You can refer to the following code snippet to get the desired output.
function out=my_func(T,idx)
out=[];
for i=1:size(T)
temp=T{i};
out=[out temp(idx(i))];
end
end
Hope this helps you.

카테고리

Help CenterFile Exchange에서 데이터형에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!