Insert array into larger array with unknown number of dimensions
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Rik
2023 年 11 月 3 日
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 :)')
その他の回答 (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!