I have uploaded both vectors, vector data_f = 1, vector data_b = 2. I will make an addition to my question, in my original question i said for second vector data from index 120 to end of vector 1 shall be copied. Since Now i have attached data, you will see some zeros in second column of each vector, these zero represents stops. So I would like to get data of vector 1 from index 1 to 100 and data of vector 2 from index 120 to first zero. I just don't want index numbers to be copied in third vector, I actually want the data in third vector of these index numbers.
How to get data some data from one vector and save it in another vector
조회 수: 16 (최근 30일)
이전 댓글 표시
I have 2 vector files having 2 columns in each vector. I wrote a code which finds the index number for each vector which needs to be copied from each of them and shall be used to create a 3rd vector. For example i = 100 is index number of vector 1 and b = 120 is index number of vector 2. I want to copy data of vector 1 from index 1 to 100 and and data of vector 2 from index 120 to last index of vector 2 and put them in a new vector. In new vector, data of vector 1 has to come first and shall be followed by data extracted from vector 2. I am not sure how to do that. Can someone help with this.
Regards
채택된 답변
Koundinya
2018년 9월 3일
The file ( Data_f_b.mat) you have attached has two 500x2 vectors data_b and data_f. To copy the elements from row index 1 to 100 of the first vector data_f into another vector:
thirdVector=data_f(1:100,:);
For extracting the required elements from second vector data_b:
% store the values of data_b vector from row index 120 into an array
temp=data_b(120:end,:);
% element wise logical AND of the two columns of the array,to find the row having first zero element
i=find( ~(temp(:,1) & temp(:,2)) , 1);
% append the values extracted from row index 120 of data_b till the row having first zero element
thirdVector=[ thirdVector; temp(1:i,:)];
for more information about find function and performing logical operations on arrays/vectors, you can refer the documentation .
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!