MATLAB Matlab - matrix with blank space

Click For Summary
The discussion revolves around creating a specific output format in MATLAB using a predefined array. The user initializes a zero array of size 1x6 and assigns the value 2 to elements 2 through 4. However, there is a query regarding how to assign a negative value to the fifth element and retain a zero at the end, resulting in the desired output of "0 2 2 2 - 0." The conversation highlights the need for assistance in achieving this output format, particularly focusing on the correct syntax and methods in MATLAB for manipulating arrays and handling special characters like the negative sign.
Suvadip
Messages
68
Reaction score
0
r=zeros(1,6);
r(1,2:4)=2;
r(1,5)= -

rfor the above program,

I want the output as

r=

0 2 2 2 - 0

how to do this in matlab? please help
 
Physics news on Phys.org
suvadip said:
r=zeros(1,6);
r(1,2:4)=2;
r(1,5)= -

rfor the above program,

I want the output as

r=

0 2 2 2 - 0

how to do this in matlab? please help

cell array.

.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
Replies
6
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K