Create a 4D matrix with specific range values

조회 수: 4 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by