Is it possible to truncate a vector to form one of lower dimension?
14 ビュー (過去 30 日間)
回答 (2 件)
John D'Errico 2023 年 5 月 25 日
編集済み: John D'Errico 2023 年 5 月 25 日
You have two choices. First, you can extract the elements you want. Or you can delete the elements you wnat to drop. For example:
V = primes(40)
Now, drop the last 4 elements.
n = 4;
% This deletes the elements of V that you want to delete, and does so
% "in-place", in the sense that we do not assign a new vector.
V(end + (1-n:0)) = 
Next, we can decide to extract all but the last n elements. I'll just use the last version of V.
V = V(1:end - n)
In each case, we can see that the final 4 elements of V were dropped from V. As I said though, you can think of the second case as where I extracted the elements I wanted to save, while in the first case, I indicated the elements I wanted to delete.