How to select specific data from one matrix and place it in another

1 回表示 (過去 30 日間)
stelios loizidis
stelios loizidis 2020 年 11 月 2 日
コメント済み: Ameer Hamza 2020 年 11 月 2 日
Hello,
I have the following problem. I have a large matrix A (1X960). At positions 336 I have the prices for 14 consecutive Mondays. That is, every Monday has 24 prices. Then, in the next 312 positions I have data for 13 consecutive Fridays (every Friday has 24 prices) and in the last 312 positions I have data for 13 consecutive Saturdays (every Saturday has 24 prices).
What I'm trying to do is this: In a new matrix B I want to put the data in order. That is, to enter first the 24 values ​​of Monday, then the 24 values ​​of Friday and then the 24 values ​​of Saturday. This should continue for all the data in matrix A. Your help is important !!!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日
Try this
data = 1:960;
A = reshape(data, 24, []).';
B = zeros(size(A));
B(1:3:end, :) = A(1:14, :);
B(2:3:end, :) = A(15:27, :);
B(3:3:end, :) = A(28:40, :);
B = reshape(B.', 1, [])
  4 件のコメント
stelios loizidis
stelios loizidis 2020 年 11 月 2 日
It. works!!!!!!!Thank you very much for the valuable help!
Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日
I am glad to be of help! :)

サインインしてコメントする。

その他の回答 (2 件)

Cris LaPierre
Cris LaPierre 2020 年 11 月 2 日
See Ch 5 of MATLAB Onramp.

dpb
dpb 2020 年 11 月 2 日
The following can be optimized, but if I understand you want the data reordered by hour for each day, then the basic idea for any number of days and observations per day assuming every daily observation is complete set of numPerDay.
nDays=[14,13,13];
numPerDay=24;
dIx=nDays*numPerDay;
ix1=[1 cumsum(dIx(1:numel(nDays)-1))+1];
for i=1:24
B(i,:)=A(ix1);
ix1=ix1+1;
end

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by