Suppose O=ones(n) Now how can I insert a row of all 8’s between rows (n-3) and (n-2) of matrix O and insert a column of all 8’s between columns 1 and 2 of matrix )

 Akzeptierte Antwort

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 23 Nov. 2017
Bearbeitet: Kaushik Lakshminarasimhan am 24 Nov. 2017

0 Stimmen

N = 10;
X = ones(N); % create a matrix of 1s
X = [X(1:N-3,:) ; 8*ones(1,N) ; X(N-2:end,:)]; % add a row of 8s between (N-3)th and (N-2)th row
X = [X(:,1) 8*ones(N+1,1) X(:,2:end)]; % add a column of 8s between 1st and 2nd columns

9 Kommentare

Chung Di
Chung Di am 23 Nov. 2017
Error: File: ones.m Line: 4 Column: 15 Expression or statement is incorrect--possibly unbalanced (, {, or [.
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 23 Nov. 2017
Can you show us your code?
Chung Di
Chung Di am 23 Nov. 2017
Have tried same as you, Nothing changed
Chung Di
Chung Di am 23 Nov. 2017
This one
Walter Roberson
Walter Roberson am 24 Nov. 2017
Copy and paste Kaushik Lakshminarasimhan's code. Spacing is important.
Chung Di
Chung Di am 24 Nov. 2017
Where is the fault ? I tried his code
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 24 Nov. 2017
There should be no space between X and the parenthesis in X(1:N-3,:).
Chung Di
Chung Di am 24 Nov. 2017
It will be really helpful if you use comments beside the code, so that I can understand the code, rather than copy paste Thank you so much
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 24 Nov. 2017
I didn't add comments because I thought it was self-explanatory. Anyway, I have edited my answer to include comments.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by