Putting a variable string into a comma delimited string

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.

 採用された回答

dpb
dpb 2018 年 8 月 16 日

1 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by