How can you save a 1 by 3 array in each position of a 4D array?

40 Ansichten (letzte 30 Tage)
Mitchell
Mitchell am 15 Dez. 2025 um 15:05
Kommentiert: Mitchell am 15 Dez. 2025 um 18:05
I am working on an interpolation project where I have 4 variables, each representing a dimension of a 4D array. There are three seperate values that coincide with each coordinate of the 4 dimensional array. The only way I have been able to make this work so far is that I currently have 3 seperate 4D arrays, each with the same set of variables but with one of the 3 values stored at each coordinate. The issue is that this creates a lot of reduntanat data and significantly increases the file size, while also increasing the computational resource requirement by running the interpolation 3 seperate times. I would like to only have one 4D array, with each coordinate housing a 1x3 with all 3 data points needed. Is this possible? If so, what is the best approach? I have approached this using Cell arrays, but I still run into errors of trying to assign 1x3 in a 1x1 space or with trying to assign doubles in the cell array.
  3 Kommentare
Catalytic
Catalytic am 15 Dez. 2025 um 16:41
Bearbeitet: Catalytic am 15 Dez. 2025 um 16:41
@Mitchell We can't understand your question clearly. Too many words. Not enough code.
Mitchell
Mitchell am 15 Dez. 2025 um 18:01
@Matt J thank you, this was more of a conceptual issue of higher dimensions arrays for me. Between your comment here and your answer I have my head wrapped around it now.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 15 Dez. 2025 um 16:35
Bearbeitet: Matt J am 15 Dez. 2025 um 16:37
I would like to only have one 4D array, with each coordinate housing a 1x3 with all 3 data points needed. Is this possible?
You could have a 5D array, where the 5th dimension are the 3 values. Then you can interpolate the 5D array in one go, e.g.,
V=rand(4,4,4,4,3);
xq=linspace(1,4,8);
F=griddedInterpolant(V);
Vq = F({xq,xq,xq,xq,1:3}) ; %upsample by interpolation
whos V Vq
Name Size Kilobytes Class Attributes V 4x4x4x4x3 6.000 double Vq 8x8x8x8x3 96 double
I'm not optimistic this will do much for you beyond keeping everything compactly in a single array variable, but on the other hand, I don't see any signs you had any inefficiency to begin with (see my comment above).
  1 Kommentar
Mitchell
Mitchell am 15 Dez. 2025 um 18:05
Perfect. Yeah I am seeing that now, with your answer here and @the cyclist below, I compared my 3 seperate 4D arrays to a 5D array and to a 4D cell array and they all come out to essentially the same storage requirements, there are just differences in how to interpolate/access the data. For my application going to the 5D array will work best now that I have my head wrapped around it. Simple enough, sometime you just need someone else to point it out. Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

the cyclist
the cyclist am 15 Dez. 2025 um 15:30
This code creates a 4-dimensional cell array, and stores a 1x3 numeric vector in one of the elements
c = cell(2,3,5,7);
c{1,2,3,4} = rand(1,3);

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by