Why does matlab create a single row when creating a matrix of multiple columns?

I have to following problem: In reality i have two columns consisting of 250k rows, but i fail to creat a matrix by just using matrix = [column1 column2]. Did i change something in my settings? See the following simple example of my problem
a = [1:10]'
b = [1:10]'
c = [a b]
The answer is
"Columns 1 through 18
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8
Columns 19 through 20
9 10 "
instead of a matrix consisting of two columns. What is going on here?

6 Comments

The code you posted works correctly for me, and produces ‘c’ as a (10x2) matrix.
This question/thread needs to be deleted. I'm did something wrong in my code after creating the matrix.
I can’t find a normdata function in the online documentation. (It’s for R2019a, however it should cover all recent releases.)
See if running this line from a script or your Command Window reveals anything:
which normdata -all
That’s the only thing I can think of that might resolve the issue.
Original question:
In case if the OP edits the content of the question.
I have to following problem: In reality i have two columns consisting of 250k rows, but i fail to creat a matrix by just using matrix = [column1 column2]. Did i change something in my settings? See the following simple example of my problem
a = [1:10]'
b = [1:10]'
c = [a b]
The answer is
"Columns 1 through 18
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8
Columns 19 through 20
9 10 "
instead of a matrix consisting of two columns. What is going on here?
I did the following wrong: A matrix consisting of 250k rows and 4 columns, when I wanted to delete a number of rows I used normdata(deleterows) = [], while I should've used normdata(deleterows,:)=[].
Thank you so much for replying madhan ravi and star strider. Sorry for any inconvenience.
No need for an apology, mistakes are inevitable sometimes.

Sign in to comment.

Answers (1)

[a,b] - you were concatenating two row vectors horizontally which results in a row vector, instead do:
c = [a(:) b(:)]
%or
c = [a;b].'
Also this works:
>> a = [1:10]'
b = [1:10]'
c = [a b]
a =
1
2
3
4
5
6
7
8
9
10
b =
1
2
3
4
5
6
7
8
9
10
c =
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
>>

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 7 Apr 2019

Commented:

on 7 Apr 2019

Community Treasure Hunt

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

Start Hunting!