Matlab, adding columns in matrices

Click For Summary
SUMMARY

The discussion focuses on creating a function in Scilab to manipulate matrices by adding a row of zeros to the right and a row of sixes at the bottom of an nxn matrix. The user attempted to use the 'ones' function but encountered syntax errors. The correct approach involves using the 'zeros' function to add the required rows without manually typing each zero. The final solution proposed is to use the syntax m = [a, zeros(1, size(a, 2))] to achieve the desired matrix structure.

PREREQUISITES
  • Understanding of matrix operations in Scilab
  • Familiarity with the 'zeros' and 'ones' functions in Scilab
  • Basic knowledge of matrix dimensions and indexing
  • Experience with function creation in Scilab
NEXT STEPS
  • Explore Scilab documentation on matrix manipulation functions
  • Learn how to create and use custom functions in Scilab
  • Investigate advanced matrix operations such as concatenation and reshaping
  • Practice error handling and debugging in Scilab scripts
USEFUL FOR

Students and educators in mathematics and engineering, Scilab users working on matrix operations, and anyone developing functions for matrix manipulation in Scilab.

slugbunny
Messages
13
Reaction score
0

Homework Statement



I need to create a function for scilab which adds a row of zeros to the right of an nxn matrix, a.
I also have to add a row of 6's at the bottom but I think i have that part down.

Homework Equations



I think ones(,) is supposed to help?

The Attempt at a Solution



I have tried to use ones...

function m_1=matrix_1(a,n)
m_1=[a,0*(ones(n;1))]
endfunction

I figure if [a;ones(1,n)] gives 1 row and n columns (at the bottom), then [a,ones(n;1)] should make n rows and 1 column. Instead I have an error 'waiting for right parenthesis.'

I have also thought of zeros but I don't know how to add n rows of zeros since you must type [0;0;0...] for each row.
 
Physics news on Phys.org
Sorry, I realize there is a math & science software forum.
 
u should do
m= [a zeros(1,size(m,2))];
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 17 ·
Replies
17
Views
9K