Create cell array with the same string n-times
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (3)
Jan
am 2 Okt. 2011
C = cell(1, 5);
C(:) = {'String'};
11 Kommentare
Jonathan Deaton
am 8 Dez. 2015
You are the real winner here.
Youcef Yahiaoui
am 15 Mär. 2016
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
am 4 Jan. 2017
Yifei Wang comments to Jan:
short and good as always
Jan
am 4 Jan. 2017
Thanks. I forward the compliments to Matlab, which allows such compact and nive solutions. Try the same in C... ;-)
Pearl
am 30 Jan. 2019
awesome! Another thanks to you!
Jon
am 10 Jul. 2019
very nice technique - found this before, forgot it, and just came back again - thank you
BN
am 11 Feb. 2020
Dear Jan,
Thank you, it solve my problem too. I just want to say thanks to you.
Best Regards
Saeid
am 24 Sep. 2020
Jan's always there to give the shortest version of every solution. This helped me too!
Fabio Rondina
am 24 Sep. 2021
still usefull after 10 years. Thanks @Jan
Rob
am 17 Dez. 2021
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
am 28 Feb. 2024
Hello Jan,
Your elegant solution worked for me using the function strings.
Grzegorz Knor
am 2 Okt. 2011
repmat({'filename.mat'},1,5)
dscharf
am 17 Aug. 2023
Bearbeitet: Dyuman Joshi
am 28 Feb. 2024
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!