フィルターのクリア

As a vector into a matrix of non-uniform length

3 ビュー (過去 30 日間)
Lev Mihailov
Lev Mihailov 2022 年 4 月 5 日
回答済み: DGM 2022 年 4 月 5 日
I have an array of length n I need to make a 10xEnd matrix out of it
x = rand(1,1003); % n = 1003, 2055 , 7062
Data=reshape(x,10,[]);
Error using reshape
Product of known dimensions, 10, not divisible into total number of elements, 1003.
% the remaining 3 , 5 and 2 values ​​can be ignored
How can this be fixed?
Thank you in advance

採用された回答

DGM
DGM 2022 年 4 月 5 日
Here's one way
x = rand(1,123); % n = 1003, 2055 , 7062
m = 10; % output array height
trimlen = floor(numel(x)/m)*m; % number of elements in result
Data = reshape(x(1:trimlen),m,[]);
size(Data)
ans = 1×2
10 12

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by