Create a 4D matrix with specific range values

6 ビュー (過去 30 日間)
Bruno Silva
Bruno Silva 2017 年 8 月 29 日
回答済み: Image Analyst 2017 年 8 月 29 日
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
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?
Bruno Silva
Bruno Silva 2017 年 8 月 29 日
Ok, I understand what you mean Image Analyst.
So for my specific application I am building a Neural Network to correct a curve fitting problem. The first dimension is the sampling rate, the second one the "window size" (how many values I check at once), the third one the number of hidden layers of that NN and the forth one the number of neurons of every hidden layer. What I would like to store (if I absolutely cannot store more than one value) is the Error for each combination of those (and MATLAB provides it through a variable).
I hope I was more clear now.

サインインしてコメントする。

採用された回答

Image Analyst
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;

その他の回答 (1 件)

James Tursa
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.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by