Putting a variable string into a comma delimited string
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to insert an array of numbers and strings into a sql table. I have gotten it to work by using triple quotes around the string I want, but I want this string to be defined by a variable rather than fixed. I am trying to get this output from strjoin :
'285026, 'TC 02 13', 17.3, 17.1, 16.0, 18.0, 16.0, 18.0, 12, 13, 0.07, 0.03'
My code is as follows:
TCListBox=[TCListG1; TCListG2; TCListG3; TCListG4];
TC = TCListBox{i};
Inserted = [test_no, TC, frz, melt, freezelowpass, freezehighpass, meltlowpass, melthighpass,...
npfrz, npmelt, frzslope, meltslope];
strjoin(Inserted, ', ')
Where TCListGn are cell arrays of strings and all the other variables besides TC are numbers.
I am using R2015a.
0 个评论
采纳的回答
dpb
2018-8-16
Wrong tool for the job; while it can write flexible delimiters, I don't see any way to make it write the surrounding quotes where needed...revert to the old standby--
>> test_no=285026; TC='TC 02 13';frz=17.3;melt=17.1;freezelowpass=16.0;freezehighpass=18.0;meltlowpass=16.0;melthighpass=18;npfrz=12;npmelt=13;frzslope=0.07;meltslope=0.03;
fmt=['%d,''%s'',' repmat('%.1f,',1,6) repmat('%d,',1,2) '%.2f,','%.2f'];
s=sprintf(fmt,test_no, TC, frz, melt, freezelowpass, freezehighpass, meltlowpass, melthighpass, ...
npfrz, npmelt, frzslope, meltslope)
s =
'285026,'TC 02 13',17.3,17.1,16.0,18.0,16.0,18.0,12,13,0.07,0.03'
>>
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!