- 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"?
- 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?
- What are the values of the "new column"?
- Exactly where should this new column go? Insert into the original vector, "a"? Just isolated by itself as a standalone column vector?
- What is the final result (either a separate vector or the "a" vector with the new column inserted into it)? Give a numerical example.
How to create a new column based on values of current column
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joseph Tirado
el 26 de Ag. de 2021
Comentada: Joseph Tirado
el 26 de Ag. de 2021
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 comentarios
Image Analyst
el 26 de Ag. de 2021
Editada: Image Analyst
el 26 de Ag. de 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,
Please answer by number.
Also, why do you want to do this? What is your use case?
Respuesta aceptada
the cyclist
el 26 de Ag. de 2021
Editada: the cyclist
el 26 de Ag. de 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))
You may need to be careful in some instances when comparing floating-point numbers with exact equality. See this documentation for more details.
3 comentarios
the cyclist
el 26 de Ag. de 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))
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!