How to create a new column based on values of current column

5 Ansichten (letzte 30 Tage)
I am trying to isolate a new column based on the values of a current column, for instance: if the original column is a=[1,3,7,6.8,44,6,2,8,9]
is there a way to create a new column (including the values in between) from 6.8 through 8, without finding what cell these two values are in?
  2 Kommentare
Image Analyst
Image Analyst am 26 Aug. 2021
Bearbeitet: Image Analyst am 26 Aug. 2021
Your a is not a column. It's a row vector with 9 columns. If you insert a column into a, it will be a single number somewhere in that list. In your example, if "a" is the original row vector,
  1. What is the column you are inspecting the values of in order to isolate a new column. In other words, what is what you call the "current column"?
  2. What column is the column you want to "isolate"? ANd what does isolate mean? Extract into a new variable? Or maybe just identify the column number?
  3. What are the values of the "new column"?
  4. Exactly where should this new column go? Insert into the original vector, "a"? Just isolated by itself as a standalone column vector?
  5. What is the final result (either a separate vector or the "a" vector with the new column inserted into it)? Give a numerical example.
Please answer by number.
Also, why do you want to do this? What is your use case?
Joseph Tirado
Joseph Tirado am 26 Aug. 2021
  1. The current collumn is a list of altitudes from a drone flight that lased 2 hours I'm trying to break it into seperate columns of ascents and descents. I know what altitudes the ascents and descents start and end at but the columns are long so it would be very hard to find them manualy.
  2. I want to extract these ascents/descents into a new variable
  3. The values should be the altitudes in between the starting and ending altittudes
  4. I just need these new columns in my workspace
  5. I want a new vector, I would also like an index that states which cell values from the original column are in this new vector. Then I can extract other data such as temperature from another column that would correspond with the ascent data.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 26 Aug. 2021
Bearbeitet: the cyclist am 26 Aug. 2021
I believe this does what you want, assuming each value only appears once in the array, and you know the order they appear. You could make more robust solutions.
a = [1,3,7,6.8,44,6,2,8,9];
out = a(find(a==6.8):find(a==8))
out = 1×5
6.8000 44.0000 6.0000 2.0000 8.0000
You may need to be careful in some instances when comparing floating-point numbers with exact equality. See this documentation for more details.
  3 Kommentare
the cyclist
the cyclist am 26 Aug. 2021
It is probably one of the caveats that I included in my answer. You can solve the floating point issue by doing something like:
a = [1,3,7,6.8,44,6,2,8,9];
tol = 1.e-6;
out = a(find(abs(a-6.8)<tol):find(abs(a-8)<tol))
out = 1×5
6.8000 44.0000 6.0000 2.0000 8.0000
Joseph Tirado
Joseph Tirado am 26 Aug. 2021
Thank you so much that works!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by