Text and Number in a Matrix/row
Show older comments

I want to create a row which include both numbers and text.
Sample Code
%%%% Input %%%%%%%
Text : {'x1=','y1=','z1='}
Nos : [1:1:3];
% Sample Code
for i=1:length(Nos)
Row(1,i) = Text(i);
Row(1,i+1) = Nos(i);
end
% Need Output as below
Row = [ x1=1 y1=2 z1=3 ]; % (numbers and text in alternate columns )
% Attached image for needed output
5 Comments
Mathieu NOE
on 27 Jan 2021
hello
your code generates a cell array (size 1x6) , or was the intention to create only a string (1 x1) containing 'x1=1 y1=2 z1=3' ??
depends if the goal is to store in 6 columns (to store as excel file ? ) or create just a plain text file at the end
per isakson
on 27 Jan 2021
Hint:
>> sprintf( 'x1=%d y1=%d z1=%d', Nos )
ans =
'x1=1 y1=2 z1=3'
>>
Walter Roberson
on 28 Jan 2021
Odd, I'm sure this discussion came up in a different question yesterday, and got several responses, but I can't find it now...
Dhirendu Somani
on 28 Jan 2021
Mathieu NOE
on 28 Jan 2021
hello
would it be just one line as the format you showed or dou you intend to have column oriented vectors for x1, y1, z1 ?
if yes maybe you should put those three labels as header line in the first row and then store the vectors below (my 2 cents)
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!