[英]Reshaping a 3d matlab matrix into 2d matrix with indices and values
我在MATLAB中有一個3D矩陣。 它具有3行,4列和2個時間范圍。 請查看數據集:
>> size(filtered_data)
ans =
3 4 2
>> filtered_data
filtered_data(:,:,1) =
15 22 19 16
15 15 13 17
19 20 17 17
filtered_data(:,:,2) =
14 17 14 10
18 19 11 18
16 15 14 17
我想將此3D矩陣的所有值及其索引存儲到2維變量中。
這看起來像這樣
我嘗試使用find()
函數,但是它返回多個索引,並且要求您輸入一個需要為其計算索引的值。
是否有針對此問題的預定義MATLAB函數?
我將不勝感激。
我不相信有內置的MATLAB函數可以執行此操作,但您可以輕松完成此操作:
sz = size(filtered_data);
[x,y] = meshgrid(1:sz(2),1:sz(1));
output = [x(:).';y(:).';reshape(filtered_data(:),[],sz(3)).'];
沒有太多的神秘。 這只是重塑數據並根據大小生成索引的事實。
rows=repmat(1:size(filtered_data,1),1,size(filtered_data,2));
cols=repelem(1:size(filtered_data,2),size(filtered_data,1));
data_time_frame1=reshape(filtered_data(:,:,1),1,[]);
data_time_frame2=reshape(filtered_data(:,:,2),1,[]);
為了更靈活的方法,
data_time_frame=reshape(filtered_data(:),size(filtered_data,3),[]);
只需使用這些操作填充矩陣。 還需要一些時間來熟悉它們,以備將來參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.