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!