Using a 3D matrix to index a Cell Array without For Loops
古いコメントを表示
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 件のコメント
Stephen23
2019 年 9 月 10 日
"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
2019 年 9 月 10 日
Joshua Monteiro
2019 年 9 月 10 日
Stephen23
2019 年 9 月 10 日
If you want help, please upload some sample data in a .mat file.
Guillaume
2019 年 9 月 10 日
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
2019 年 9 月 10 日
編集済み: Stephen23
2019 年 9 月 10 日
Joshua Monteiro
2019 年 9 月 10 日
Bruno Luong
2019 年 9 月 10 日
Do you have a code with for-loop to illustrate what should be done?
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
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
2019 年 9 月 10 日
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
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
2019 年 9 月 10 日
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
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.
回答 (1 件)
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
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 件のコメント
Joshua Monteiro
2019 年 9 月 10 日
編集済み: Joshua Monteiro
2019 年 9 月 11 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

