MATLAB Answers

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

6 views (last 30 days)
Daniel Rohrer
Daniel Rohrer on 21 Nov 2020
Answered: Stephen Cobeldick on 21 Nov 2020
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});
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);
Complete_File_table = cell2table(Complete_File);
The text file looks now like this:
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


Sign in to comment.

Answers (1)

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


Sign in to comment.




Community Treasure Hunt

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

Start Hunting!