Create cell array with the same string n-times
이전 댓글 표시
Hi all,
I have another problem I haven't found any soulution for yet.
I have a list of Values and I have the name of the .mat-file the values are saved in as a string.
For example
name='Values.mat'
values =
1
2
3
4
5
Now I need to create a cell array with the name of the file for each value.
For example
>> values.filename
ans =
Values.mat Values.mat Values.mat Values.mat Values.mat
Does anybody know how I can create that cell array, size depending on how many values I have?
Thanks a lot! Oli
채택된 답변
추가 답변 (3개)
Jan
2011년 10월 2일
C = cell(1, 5);
C(:) = {'String'};
댓글 수: 11
Jonathan Deaton
2015년 12월 8일
You are the real winner here.
Youcef Yahiaoui
2016년 3월 15일
Jan Simon's answers are always the best. Whenever I look anything up, I always look for this distinct picture! Thanks, Jan Simon.
Walter Roberson
2017년 1월 4일
Yifei Wang comments to Jan:
short and good as always
Jan
2017년 1월 4일
Thanks. I forward the compliments to Matlab, which allows such compact and nive solutions. Try the same in C... ;-)
Pearl
2019년 1월 30일
awesome! Another thanks to you!
Jon
2019년 7월 10일
very nice technique - found this before, forgot it, and just came back again - thank you
BN
2020년 2월 11일
Dear Jan,
Thank you, it solve my problem too. I just want to say thanks to you.
Best Regards
Saeid
2020년 9월 24일
Jan's always there to give the shortest version of every solution. This helped me too!
Fabio Rondina
2021년 9월 24일
still usefull after 10 years. Thanks @Jan
Rob
2021년 12월 17일
Nice simple solution but it baffles me why Matlab needs two lines of code to do a simple task (or why the default is to set the contents as doubles)?
M_A_C
2024년 2월 28일
Hello Jan,
Your elegant solution worked for me using the function strings.
Grzegorz Knor
2011년 10월 2일
repmat({'filename.mat'},1,5)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!