Using a 3D matrix to index a Cell Array without For Loops
Afficher commentaires plus anciens
Hi
I have a 3D matrix (lets call it A) which indexes a cell array (called B). A stores the location of positions to access in B in the form of [cell, row, column]. I.e A(1,1,1) would reference cell 1, row 1 column 1 in B. However, A is very large, where row and column are in the thousands. Is there a way I can access all the locations of B (and store the value at that point) without using nested for loops (which takes a long time)?
Thanks
14 commentaires
Stephen23
le 10 Sep 2019
"A(1,1,1) would reference cell 1, row 1 column 1 in B"
This means that the values of A are totally irrelevant. Rather strange.
"I have a 3D matrix (lets call it A) ... However, A is very large, where row and column are in the thousands.."
And what size is its third dimension?
It would probably help if you uploaded some sample data in a .mat file.
Joshua Monteiro
le 10 Sep 2019
Joshua Monteiro
le 10 Sep 2019
Stephen23
le 10 Sep 2019
If you want help, please upload some sample data in a .mat file.
Guillaume
le 10 Sep 2019
Don't post massive screnshots. Write your matrices as code in your question (eg. see below), or attach a mat file.
Location = cat(3, [1, 3; 4, 2], [1, 1; 2, 2], [1, 2; 2, 1])
It's unclear what location refers to.
Joshua Monteiro
le 10 Sep 2019
Modifié(e) : Stephen23
le 10 Sep 2019
Joshua Monteiro
le 10 Sep 2019
Bruno Luong
le 10 Sep 2019
Do you have a code with for-loop to illustrate what should be done?
Bruno Luong
le 10 Sep 2019
Modifié(e) : Bruno Luong
le 10 Sep 2019
and A(i,j,k) contains what? I guess it related to findMax but you never tell it clearly.
B in your first post is Image?
Joshua Monteiro
le 10 Sep 2019
Bruno Luong
le 10 Sep 2019
Modifié(e) : Bruno Luong
le 10 Sep 2019
A(i,j,k) WAS location (I've changed the function slightly) but it's pretty much split into
(cell, row, column)
For a scalar triplets (i,j,k), A(i,j,k) is a single value (it cannot be then (cell, row, column)). You say "location" but what LOCATION???
- i is in what range?
- j is in what range?
- k is in what range?
- A(i,j,k) is in what range?
I guess A(i,j,k) is a CELL location. But as you says (cell, row, column) it confuses people (me) more than anything else.
Joshua Monteiro
le 10 Sep 2019
Bruno Luong
le 10 Sep 2019
Modifié(e) : Bruno Luong
le 10 Sep 2019
range := (1:x), where x is size(zzz,y), with some (other) variable zzz, the interval where the (index) variable should belong to. Example:
A = randn(3,4,5)
when I ask range specification different parameters in A(i,j,k)
- range of i is 1:3
- range of j is 1:4
- range of k is1:5
- range of A(:,:,:) is (-Inf,inf)
This allows us to understand the relationship of A and other variables.
Réponses (1)
Bruno Luong
le 10 Sep 2019
Modifié(e) : Bruno Luong
le 10 Sep 2019
Just a guess
load('Images.mat')
load('location.mat')
fileImages=cat(4,fileImages{:});
[m,n,p]=size(locationMax);
[I,J,K]=ndgrid(1:m,1:n,1:p);
NewImage=fileImages(sub2ind(size(fileImages),I,J,K,locationMax));
1 commentaire
Joshua Monteiro
le 10 Sep 2019
Modifié(e) : Joshua Monteiro
le 11 Sep 2019
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

