Create a 4D matrix with specific range values
Show older comments
I would like to create a 4D matrix with specific range values:
For the first dimension, values from [5 10 15 ... 200] so basically 5*[1:40]
For the second dimension, values from the list [8 10 20 25 40 50 100 200]
For the third dimension, values from [1 2 3 ... 10] so [1:10]
For the fourth dimension, values from [1 2 ... 50] that is [1:50]
When accessing a specific "value" of that matrix, I would like to be able to view these rages that I've set up for each dimension. For example: A(2,1,2,3) = [10 8 2 3] (in this case)
How can I do that?
Thank you.
4 Comments
James Tursa
on 29 Aug 2017
I don't really understand what it is you are trying to build. In particular, for a 4D matrix the expression A(2,1,2,3) would yield a scalar, not a vector as you have shown. How is this going to be used downstream in your code? Maybe we can suggest an alternate approach.
Bruno Silva
on 29 Aug 2017
Image Analyst
on 29 Aug 2017
Edited: Image Analyst
on 29 Aug 2017
No. You can't have a vector of 4 numbers at a particular location. You can just have a single number as James said. And you didn't even explain it - you just repeated what you said first. Let's say the "A" is a video, so we have row and column as the first two indexes, The red green or blue value as the third index, and frame number as the 4th index. So A(2,1,2,3) would be row 2, column1 of color channel #2 (blue) and you're looking at frame #3 (because the 4th index is 3). Now the blue value is one value -- it can't be a vector of 4 blue values. Please supply context as to what this 4-D array represents. When you send in indexes to A, what do those indexes represent?
Bruno Silva
on 29 Aug 2017
Accepted Answer
More Answers (1)
James Tursa
on 29 Aug 2017
Edited: James Tursa
on 29 Aug 2017
Here is one way to do what you have asked, although I don't really know if this is the best way to go about coding the real problem you are trying to solve:
D1 = 5:5:200;
D2 = [8 10 20 25 40 50 100 200];
D3 = 1:10;
D4 = 1:50;
A = @(a,b,c,d) [D1(a) D2(b) D3(c) D4(d)]
Then, e.g.
>> A(2,1,2,3)
ans =
10 8 2 3
In this case, A is actually a function handle and not a 4D matrix. But it will yield the vector result you want when passed four inputs that are used to index into your "dimension" vectors.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!