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
25 次查看(过去 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 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!