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

32 ビュー (過去 30 日間)
Shahab Khan
Shahab Khan 2018 年 8 月 30 日
回答済み: Koundinya 2018 年 9 月 3 日
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
  1 件のコメント
Shahab Khan
Shahab Khan 2018 年 8 月 30 日
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.

サインインしてコメントする。

採用された回答

Koundinya
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by