Assign value in a cell with a "oneliner"
1 回表示 (過去 30 日間)
古いコメントを表示
Hello Matlab folks,
I am trying to retrieve a cell and change some of its values with only one command line.
I have today :
>> x = {'a';'b';'c';'d';'e'};
>> x{2} = 'y';x{4} = 'z';
I am looking for something like:
>> UnknownFunction({'a';'b';'c';'d';'e'},2,'x',4,'z');
And because it is not funny otherwise, I can't create an UnknownFunction.m myself as I need to use only native Matlab function.
Any Idea ?
Thanks
0 件のコメント
採用された回答
madhan ravi
2019 年 8 月 9 日
[x{2},x{4}]=deal('x','z')
4 件のコメント
madhan ravi
2019 年 8 月 9 日
編集済み: madhan ravi
2019 年 8 月 9 日
Thanks dpb , I thought so too until the OP commented xd:
subsref({'a';'b';'c';'d';'e'},substruct('{}',{2}))
% or you can use the below ones if the user made anonymous function is allowed
retriever = @(x,y) x(y);
% ^_^ - use {} if you want
retriever({'a';'b';'c';'d';'e'},2)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!