# Change 3x1 double to 1x3 double and convert it to a string to insert in text correctly

6 views (last 30 days)
Daniel Rohrer on 21 Nov 2020
Answered: Stephen Cobeldick on 21 Nov 2020
Hi
I have following array which contains of 3x1 double:
I'd like to convert it to a string and insert it into a text with strcat which only works with strings.
for k = 1:size(Polygons,2)
Color_Interpolated{k} = num2str(Color_Interpolated{k});
end
Unfortunately, my string looks now like this:
How can I change this to a 1x3 double that the eventual output is like 0 0.667 0.667 ? I need to convert it later to a string.
Below I combine all the strings together, and I need to transpose it to match the dimensions. I used reshape too, with the same results.
for k = 1:size(Polygons,2)
Complete_File{k} = strcat(Shape, Color_Interpolated{k});
Complete_File{k} = transpose(Complete_File{k});
Complete_File{k} = strcat(Complete_File{k}, Geometry,...
Assoc_Polygons{k}, coordIndex);
end
Complete_File_table = cell2table(Complete_File);
writetable(Complete_File_table,'Test.txt');
The text file looks now like this:
Shape
{
appearance Appearance {
material Material {
Color 0 }
}
geometry IndexedFaceSet
So the color is not inserted correctly, I think if the cells in Color_Interpolated are correct the text insert will be correct too.
Best regards

Stephen Cobeldick on 21 Nov 2020
v = [0;2/3;2/3]
v = 3×1
0 0.6667 0.6667
num2str(v.')
ans = '0 0.66667 0.66667'
or
sprintf('%g %g %g',v)
ans = '0 0.666667 0.666667'

R2020a

### Community Treasure Hunt

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

Start Hunting!