Question:

Help with the horzcat function and comma's in matlab needed ASAP!!!?

by  |  earlier

0 LIKES UnLike

HELP!!

I am trying to use the disp function along with the horzcat function. so I have 3 vectors:

a= (6 2 3)’

c= (4 5 8)’

b= (1:length(a))’

d= horzcat(a , b ,c)

and so d looks something like this:

6 4 1

2 5 2

3 8 3

Then I want to put commas between these numbers either by using the display function or else. However if I use the display function it gives me an error that the horzcat arguments are not of the same dimension which I assume mean that the ‘ ,’ also needs to be defined as a vector of the same dimension . Does anyone know a way to achieve the values with the commas in between?????????? I would really appreciate your help.

 Tags:

   Report

1 ANSWERS


  1. Best way is to use fprintf, like this (for your example):

    fprintf(1, '%f, %f, %f\n', d');

    However, if you really need to put commas into the variable itself, then you can use strings.

    com = repmat(', ', [3,1]);

    str = [num2str(a(:)), com, num2str(b(:)), com, num2str(c(:))];

    disp(str);

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions