How do I swap section of cells within a column in a struct

3 ビュー (過去 30 日間)
DavidL88
DavidL88 2020 年 8 月 15 日
コメント済み: DavidL88 2020 年 8 月 15 日
Hi
I have a 1x144 struct with 7 fields called Test. In one of these fields (Test.Name) I have a column of cells with names of electrodes. I want to swap two sections of these column. Both sections are 32x1 cells (MyData1 and MyData2). Can anyone advise how to do this? Going on other posts here I tried simply - Test(65:96).Name = Test(97:128).Name but get message (Expected one output from a curly brace or dot indexing expression, but there were 32 results). Tried other ways such as loops but no progress.
DataMat = in_bst_data(sFiles.ChannelFile);
Test = DataMat.Channel;
MyData1 = {Test(65:96).Name}'
MyData2 = {Test(97:128).Name}'

採用された回答

Matt J
Matt J 2020 年 8 月 15 日
That should work fine:
>> [Test(1:6).Name]=deal('dog','cat','fish','bird','horse','rat');
>> MyData1 = {Test(1:3).Name}', MyData2 = {Test(4:6).Name}'
MyData1 =
3×1 cell array
{'dog' }
{'cat' }
{'fish'}
MyData2 =
3×1 cell array
{'bird' }
{'horse'}
{'rat' }
  3 件のコメント
Matt J
Matt J 2020 年 8 月 15 日
[Test(1:6).Name]=deal(Test([4:6,1:3]).Name)
DavidL88
DavidL88 2020 年 8 月 15 日
That worked thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by