Clear Filters
Clear Filters

creating a table in matlab

1 view (last 30 days)
maya
maya on 25 Feb 2013
Hi,
I am new to matlab so pardon me if this question seems simple.
I have 6 vectors(they are number with decimals) and I am asked to display the first 3 rows of each vector in a table with a title for each vector. is there a simple way to do it, considering that I am not supposed to use loops.

Answers (4)

Youssef  Khmou
Youssef Khmou on 25 Feb 2013
hi maya,
this is not complete answer, so try to figure out how to print the 6 vectors :
we create 2 random vectors or lets say rand matrix and use 'disp' command :
>> disp(' test1 test2');disp(rand(2,2))
control the first 'disp' run to allign the output and put the 6 vects in one matrix .

Azzi Abdelmalek
Azzi Abdelmalek on 25 Feb 2013
Edited: Azzi Abdelmalek on 25 Feb 2013

Shaun VanWeelden
Shaun VanWeelden on 25 Feb 2013
Without loops, there is no realllly simple way, that being said, there are a few shortucts, the code below should get you started:
vec=[41 56 87 90 24 25 0 52]
CellArray(2:4,1) = num2cell(vec(1:3))';
CellArray{1,1}='Vector 1'
I would check out the MATLAB help and some videos about cell arrays, honestly they can be a pain in the butt to learn for the first time, but once you do, they can be amazingly helpful. Let me know if you don't understand what's happening above!

Image Analyst
Image Analyst on 25 Feb 2013
As yet another way, you could print them out using fprintf(). It really depends on what form your table takes and where it is supposed to be displayed, like on a GUI, in the command window, in a text file, etc.

Categories

Find more on Numeric Types 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!