# Vector access and manipulation

6 ビュー (過去 30 日間)
Fidele Adanvo 2020 年 11 月 22 日
コメント済み: Fidele Adanvo 2020 年 12 月 7 日
Hello everyone,
Let's say I'm doing a certain task and have to call a function.
Let's also say that there is a vector Vec = [a b c] that can contain Vec=[0 0 0] or internal numbers for example Vec=[ 3 8 10].
Let's say the output of function is Out (Vec (1)).
Of course when the Vec Vector is null Out (0) does not exist.
Is there a way to tell matlab not to consider this output Out (0)?

サインインしてコメントする。

### 回答 (1 件)

Nora Khaled 2020 年 11 月 22 日
do you only discard the function output for a vector of all zeros? or for zero elements.
why not use if-else
f =@(x) x.^2;
Vec=[3 8 10];
if sum(Vec)==0
disp('vector of zeros')
else
f(Vec)
end
##### 1 件のコメント表示非表示 なし
Fidele Adanvo 2020 年 12 月 7 日
With this answer we will assume that Vec=[0 8 10]; and A to another vector
and that I want to ignore access to A(Vec(1)). That logically does not exist A(0)

サインインしてコメントする。

### カテゴリ

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by