フィルターのクリア

How do we shift the cell of a variable and replace it by NaN?

2 ビュー (過去 30 日間)
Anu
Anu 2022 年 1 月 25 日
コメント済み: Anu 2022 年 1 月 25 日
I have a variable x. The x contains a large number of values. When I open x in the workspace, I see the first value is in the 1st cell, second value is in the second cell and so on. I want to shift the the values from celll 1 to cell 5 and replace the first five cells with NaN. How will we do this?
For example, x = 20, 30, 40, 50, 60
I want to shift these values, therefore my new x after shifting will be NaN NaN NaN NaN NaN 20, 30, 40, 50, 60
Any help will really be appreciated.
Thanks.

採用された回答

DGM
DGM 2022 年 1 月 25 日
It depends what you mean by "shift". Consider the two examples:
x = 20:20:200
x = 1×10
20 40 60 80 100 120 140 160 180 200
a = [NaN(1,5) x] % simply concatenate
a = 1×15
NaN NaN NaN NaN NaN 20 40 60 80 100 120 140 160 180 200
b = [NaN(1,5) x(1:end-5)] % shift right and fill with NaN
b = 1×10
NaN NaN NaN NaN NaN 20 40 60 80 100
  1 件のコメント
Anu
Anu 2022 年 1 月 25 日
thanks so much, @DGM. For now, I want to do the first option, but good to know the later one for the future.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAdding custom doc についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by