- 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2021-8-26
编辑:Image Analyst
2021-8-26
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?
采纳的回答
the cyclist
2021-8-26
编辑:the cyclist
2021-8-26
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 个评论
the cyclist
2021-8-26
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))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!