Create a 4D matrix with specific range values
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2017-8-29
编辑:Image Analyst
2017-8-29
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?
采纳的回答
Image Analyst
2017-8-29
You can store the error
In quadruple loop over all 4 parameters...
theActualValue = whatever(..........
thisError = SomeFunctionToComputeError(theActualValue, theExpectedTrueValue);
% Save error for this combination of parameters.
A(samplingRate, windowSize, numLayers, numNeurons) = thisError;
0 个评论
更多回答(1 个)
James Tursa
2017-8-29
编辑:James Tursa
2017-8-29
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!