MATLAB: How to get data some data from one vector and save it in another vector

copying datadata importMATLAB

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

Best Answer

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 .