using parts of matrix with different sub-vectors (Matlab)

Dear members
I have a vector V divided on sub-vectors
And I have also a matrix H divided on sub-matrices
I want shifting the sub matrices at each time with the sub-vectors

1 Kommentar

I'm glad my answer helped you solve the problem. I'm less glad you decided to edit away parts of your question. I have put a copy of it below. Feel free to put it back the way it was.
using parts of matrix with different sub-vectors (Matlab)
Dear members
I have this vector V divided on sub-vectors:
And I have also this matrix H:
I have this parameters:
T=5, M=5, N=10
For the first part of the matrix which is in the green screen, I use the vector [V0 V1].
For the second part of the matrix which is in the orange screen, I use the vector [V1 V2].
For the third part of the matrix which is in the black screen, I use the vector [V2 V3].
It means for the first step I always work on the first N rows and N*2 columns. Then I shif the screen with M columns and N rows.
I tried to program that like this:
sz=numel(V);
q=sz/N;
for ess=1:q % q here = 3
if ess == 1
Hc = H(1:T*2,1:N*2); % Hc=H(1:10,1:20)
else if ess ==2
Hc = H(T+1:(T*2)+M,(T*2)+1:(T*2)+(N*2)); % Hc=H(6:15,11:30)
else
Hc = H((T*2)+1:end,(N*2)+1:end); % Hc=H(11:20,21:40)
end
But how can I program this loop in general way if I have a long vector V

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Rik
Rik am 16 Jun. 2021
Shouldn't something like this work?
Hc = H((T*(ess-1))+1:end,((N*2)*(ess-1)+1:N);

6 Kommentare

@Rik Unfortunately not !
It should be possible to find a formula to generate the correct indices.
Can you come up with a formula to find the upper left corner of the sub-matrix?
@Rik The only formula is to work firstly on the first sub matrix using the first N rows and the first N*2 columns. Then, at each time we shift the previous sub matrix with M columns and N rows.
So what about this:
r=(ess-1)*N;c=(ess-1)*M
H( r+(1:N) , c+(1:2*N) )
@Rik what is r and c !!!!
I don't understand what you wrote
Since we were talking about rows and columns, and they are used to index the rows and columns I thought the names would be clear.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 15 Jun. 2021

Kommentiert:

Rik
am 18 Jun. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by