How to save some values from one vector to another

4 vues (au cours des 30 derniers jours)
Pouyan Msgn
Pouyan Msgn le 17 Août 2020
Commenté : Stephen23 le 17 Août 2020
I have 2 files and I saved them in one vector:
clc
clear all
D1=importdata('M1.txt');
t1=D1(:,1); A1=D1(:,2);
D=importdata('M2.txt');
t=D(:,1); A=D(:,2);
Af=[A1
A];
In this case Af will be a 1004 X 1 vector.
Now if I want to save all values between 0 and 0.05 in Af in another vector; how should I do that ?
I know I have to do it in a for loop but I failed. Can anyone help me ?
  1 commentaire
Stephen23
Stephen23 le 17 Août 2020
"In this case Af will be a 1004 X 1 vector. "
Given that each of the files contains 5002 rows, I suspect you mean that Af will have 10002 rows.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 17 Août 2020
Modifié(e) : Stephen23 le 17 Août 2020
"I know I have to do it in a for loop but I failed."
Why do you need to use a loop? The MATLAB way is to use simple logical indexing:
Af = [A1;A];
idx = Af>=0 & Af<=0.05;
new = Af(idx)
Basic MATLAB concepts, like how to use indexing, are introduced here:

Plus de réponses (0)

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by