필터 지우기
필터 지우기

Shifting columns in matrix Matlab

조회 수: 4 (최근 30일)
Afluo Raoual
Afluo Raoual 2021년 2월 12일
편집: Afluo Raoual 2021년 3월 16일
Dear members,
I have a matrix in which its tril and triu are zeros
And I want to shift up its rows
How can I program it in Matlab please?
  댓글 수: 3
the cyclist
the cyclist 2021년 2월 12일
What is in the matrix locations that are "empty" in your top image of H. (An element of a numeric array cannot be empty.)
Can you upload the matrix H in a MAT file?
Afluo Raoual
Afluo Raoual 2021년 2월 12일
@the cyclist The empty elements are replaced all by zero elements

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2021년 2월 13일
편집: the cyclist 2021년 2월 13일
Slightly simpler version of @Nora Khaled's idea. It will also generalize to an (N-1) X N array in a way that I believe makes sense, in case that is important.
[~,c] = size(H);
r = c/2;
M = zeros(r,c);
for i=2:2:c
j = i/2;
M(:,i-1:i) = H(j:j+r-1,i-1:i);
end
You don't really need to define r or j as a separate variable, but I think it is a bit clearer.
Also, if you did need this for large arrays, it is more memory-efficient to preallocate M as I did, rather than building it by continually appending.
  댓글 수: 1
Afluo Raoual
Afluo Raoual 2021년 2월 13일
Thank you so much. It works

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nora Khaled
Nora Khaled 2021년 2월 12일
clear all;
clc
H=[0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
1 1 1 0 0 1 0 0 0 0
1 0 0 1 1 0 0 1 0 0
1 1 0 0 1 1 1 0 0 1
0 0 1 1 1 0 1 1 1 0
0 0 0 0 0 1 0 0 1 1
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 1 1];
[~,c]=size(H);
j=0;
M=[];
for i=1:2:c
j=j+1;
M=[M H(j:j+4,i:i+1)];
end
  댓글 수: 1
Afluo Raoual
Afluo Raoual 2021년 2월 13일
Thank you so much. It works

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by