run through a cell content in single loop

조회 수: 1 (최근 30일)
REN
REN 2011년 3월 7일
Hello,
I try to get data from cell A by its index value(stored in B).
A = cell(1, 10);
B = [1 3 6 8];
How to get first 3rd, 6th, 8th cell content in a single loop?
I tried A{B}, it doesn't work.
If A is a large cell, A = cell(1, 50000); B = [many indice here], I got error:
AA = A(B);
??? Index exceeds matrix dimensions.
  댓글 수: 1
Daniel Shub
Daniel Shub 2011년 3월 7일
Are you sure you did not screw something up?
A = cell(1, 50000);
B = randi(50e3, [1, 500e3]);
AA = A(B);
works fine for me. What is the max of your B?

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

채택된 답변

Matt Tearle
Matt Tearle 2011년 3월 7일
Do you want AA to be a cell array or whatever type the contents are (assuming they're all the same)? In the former case AA = A(B) (with parentheses). In the latter, AA = [A{B}] (with curly braces).
But it sounds like your error message is a simpler issue: the values of B aren't between 1 and numel(A).

추가 답변 (1개)

REN
REN 2011년 3월 7일
I guess my MATLAB has problem, it crashed several times last weekend.
Maybe some config files were changed?
Not sure how to restore the settings.
Thanks Matt and Daniel !

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by