Saving a value from matrix B, indexed by matrix A

2 Ansichten (letzte 30 Tage)
sprklspring
sprklspring am 8 Jun. 2018
Kommentiert: Majid Farzaneh am 12 Jun. 2018
Hello all, I have a pretty basic question which causes me problems. I have a 1x100 vector A. Each cell of this vector contains a different number, i.e. A(1,1) = 2010, A(1,2) = 3834, etc. Now, this values of a vector A are indeces, which index a column of vectors contained in all cells of a matrix B; matrix B is an 8x8 cell matrix, and each of its cells contain a 1x4000 vector of numbers. Could you tell me what is your idea of finding values indexed by the vector A in all of the cells of matrix B?
Update from below: all the numbers in 'indeces' vector are supposed to be found in each cell of the 8x8 matrix 'cell', i.e. I expect the output from each cell of the output matrix (the 'What you want' one) to be a vector of 1x132, providing the sample files I attached. Here it seems like I overwrite and save just the 132th value, since the output is just an 8x8 matrix of numbers, instead of 8x8 cell matrix of 1x132 vectors.
  2 Kommentare
James Tursa
James Tursa am 8 Jun. 2018
Please provide a short example of inputs and desired output(s) so we are clear what you want.
sprklspring
sprklspring am 8 Jun. 2018
Here you can see a sample. In 'indeces' we have 132 values in 1x132 vector. These 132 numbers correspond with columns in 'cells', i.e., value 2781 (1,1 in 'indeces') indicates that the value I need to save is stored under column 2781 in 'cells{1}' - in this case, this number is 9. I have 64 cells in my 'cells' matrix, and I need to perform this search and save for every cell, with all of the numbers indicated in 'indeces'.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Majid Farzaneh
Majid Farzaneh am 8 Jun. 2018
Bearbeitet: Majid Farzaneh am 8 Jun. 2018
Hi, you can use a for loop for B like this:
for i=1:numel(B)
...
end
Then, determine the index by A, like this:
idx=A(1,1); % for example
Get B values like this:
What_you_want(i)=B{i}(idx)
  1 Kommentar
Majid Farzaneh
Majid Farzaneh am 8 Jun. 2018
for i=1:numel(B)
idx=A(1,1); % for example
What_you_want(i)=B{i}(idx)
end
At the end you have 64 values in What_you_want matrix for 64 cells in B.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

sprklspring
sprklspring am 11 Jun. 2018
Thanks Majid! You helped a lot, it's just one questions keeps bugging me: all the numbers in 'indeces' vector are supposed to be found in each cell of the 8x8 matrix 'cell', i.e. I expect the output from each cell of the output matrix (the 'What you want' one) to be a vector of 1x132, providing the sample files I attached. Here it seems like I overwrite and save just the 132th value, since the output is just an 8x8 matrix of numbers, instead of 8x8 cell matrix of 1x132 vectors. Do you know what I mean?
  4 Kommentare
sprklspring
sprklspring am 12 Jun. 2018
Hi Majid, I got what I wanted. Thanks for your help!
Majid Farzaneh
Majid Farzaneh am 12 Jun. 2018
You're welcome

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by