Insert array into larger array with unknown number of dimensions
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kevin Kleiboemer
le 3 Nov 2023
Commenté : Kevin Kleiboemer
le 3 Nov 2023
Hello,
I want to evaluate measurement data with varying number of input parameters. Each parameter results in a dimension of my measured datapoints. There are at least five, but up to eight parameters, ergo dimensions of my data points. When reading the data from its file, I need to loop through two always existing dimensions (the left ones). In each loop, I read an array, that has three to six dimensions. So it looks like
for n=1:nparameter(1)
for m=1:nparameter(2)
data(n,m,:) = datasource.(parameter_a(n)).(parameter_b(m));
end
end
Now, the data(n,m,:) only allows a single dimension vector to be inserted, but the datasource will have multiple dimensions. Using the code above results in the error message
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
How can I read my data fields? I know the number of dimensions and their size a few lines, before this code is executed.
0 commentaires
Réponse acceptée
Rik
le 3 Nov 2023
Alternatively, you can use this trick:
data = zeros(10,10,3,4,5);
trailing = repmat({':'},1,ndims(data)-2);
data(1,1,trailing{:}) = ones(1,1,3,4,5);
disp('it works :)')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!