How to replace elements of matrix by elemts from array

조회 수: 2 (최근 30일)
Dmitry Timofeev
Dmitry Timofeev 2019년 12월 27일
답변: Andrei Bobrov 2019년 12월 27일
k = 8;
x = 1:2500; % array
h = 1:257;
newV = (0:length(x)-1).'*k+h;% matrix of indices
I have created matrix of indices, wich contains indexes of array x. Now I want to replace all elements of matrix by elemts from array x.
It should like this:
NewV = [x (1) x (2) x(3) ... ; x(9)... ; x(17)... ; x(25)... ]

답변 (2개)

Akira Agata
Akira Agata 2019년 12월 27일
Basically, this task can be done by:
NewV = reshape(x,8,[])';
But in your case, length(x) can NOT be devided by k (=8). So you should adjust length(x) by padding/removing some elements.
  댓글 수: 2
Dmitry Timofeev
Dmitry Timofeev 2019년 12월 27일
How I can remove this elements from array x?
Dmitry Timofeev
Dmitry Timofeev 2019년 12월 27일
편집: Dmitry Timofeev 2019년 12월 27일
I've changed size of matrix 'newV'
clear; clc;
v = 1:257;
n = 100;
k = 8;
x = 1:2500;
h = 1:257;
n = length(1:8:length(x)-length(h));
NewV = (0:n-1).'*k + v;
NewV = reshape(x,8,[])';
But It still doesn't work.
How I should replace elements from array 'NewV' in this method:
NewV = [x (1) x (2) x(3) ... x(257); x(9)...x(265) ; x(17)... x(273); x(25)...x(281) ]
?

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


Andrei Bobrov
Andrei Bobrov 2019년 12월 27일

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by