filling a internal value of a matrix

Hi I have the following matrix
I=
0 1 0 0
0 0 1 1
0 1 0 0
0 0 1 0
I want the following output:
0 1 0 0
0 1 1 1
0 1 1 0
0 0 1 0
Is there any easy way to do that,easily?
Thanks

 Akzeptierte Antwort

Matt Fig
Matt Fig am 26 Jun. 2011

0 Stimmen

This function will help you: FINDSUBMAT. Here is an example:
I=[0 1 0 0
0 0 1 1
0 1 0 0
1 0 0 0
0 0 1 0
1 0 0 0
0 0 1 0];
idx = findsubmat(I,[1 0 1]'); % Available at the above link...
I(idx+1) = 1
I =
0 1 0 0
0 1 1 1
0 1 0 0
1 0 0 0
1 0 1 0
1 0 1 0
0 0 1 0

Weitere Antworten (1)

Paulo Silva
Paulo Silva am 26 Jun. 2011

0 Stimmen

I(6)=1;
I(11)=1;
or
I([6 11])=1

3 Kommentare

Mohammad Golam Kibria
Mohammad Golam Kibria am 26 Jun. 2011
What to do if I want to fill all those zeros with of the
form :
1
0
1
=
1
1
1
Walter Roberson
Walter Roberson am 26 Jun. 2011
Please give an example of the desired output matrix.
Mohammad Golam Kibria
Mohammad Golam Kibria am 26 Jun. 2011
I=
0 1 0 0
0 0 1 1
0 1 0 0
0 0 0 0
0 0 1 0
0 0 0 0
0 0 1 0
output:
0 1 0 0
0 1 1 1
0 1 0 0
0 0 0 0
0 0 1 0
0 0 1 0
0 0 1 0
This is an example, your previous code will work for
this simple matrix, but in case when my matrix is larger
and I dont know where this type of pattern
1
0
1
exists and then replace the middle 0 to 1 as above

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by