replacing rows with values from another matrix

조회 수: 7(최근 30일)
caroline bourn 2021년 3월 14일
댓글: caroline bourn 2021년 3월 17일
Hi,
i have 1 3625 x 1 matrix. i have used the following code to flip values based on an index. It gives me a matrix of 1185x1. (as expected)
next =1;
% figure out origin and flip the x and y axis accordingly
for i=1: length(pts)
x_values = flip(x(next:pts(i))) % this finds the walks that start at the other side of origin
next=pts(i);
end
this gives me the output i expect.
now where i am having trouble is with replacing the values in my previous matrix with these new values....
pts is 1250, 2434, 3624.
the new matrix x_values is from pts 1250 - 2434.
댓글 수: 2표시숨기기 이전 댓글 수: 1
caroline bourn 2021년 3월 16일
pts is [ 1250, 2435, 3624] this is the change in time (indicating a new test)
i know it is over-ridding. i dont want it to... i want the expected output to look like this.

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

채택된 답변

ANKUR KUMAR 2021년 3월 16일
Since you have not attached any speciific data, I am generating random values and indices to change.
clc
clear
original_mat=randi(20,1,100);
new_mat=randi(20,1,30);
index_to_change=45:74;
original_mat(index_to_change)=new_mat;
Hope this helps.
댓글 수: 3표시숨기기 이전 댓글 수: 2
caroline bourn 2021년 3월 17일
hi thank you for this! much appreciated. the problem is with this code i am writing it to apply to any file i get. the position of index relies on pts which in this particular case is calculated using find change pts. pts is [1250, 2435, 3624]. i also want to stay using text files.....

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

범주

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by