Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fixing a number in a matrix

Subject: fixing a number in a matrix

From: Ozge Taskan

Date: 8 Jun, 2010 17:42:07

Message: 1 of 2

Hi,

I am trying to prepare a matrix, I have a for loop and in this loop I increase every number in the matrix by one and make some calculations, when I finish my calculations then I need to say fix one number in my matrix and make zero the other numbers in the same row. Same calculations need to be done again from the beginning however these zero values mustn't change. I need to fix these zero values and try to put these numbers in quarantine and these numbers should not be affected by any calculations.
for example I will start with
s=zeros(5,5)
I will find s(1,5) should be 1 then I will fix all numbers as 0 in this row except 5th column number, s(1,1)=s(1,2)=s(1,3)=s(1,4)=0. Then continue my calculations by increasing each number except these 0 values by 1, these zeros will never be affected from any calculations? How can I do that?

I hope my question is clear. I really need help. I appreciate your help and time. Thank you very much in advance.

Oz

Subject: fixing a number in a matrix

From: Walter Roberson

Date: 8 Jun, 2010 20:11:47

Message: 2 of 2

Ozge Taskan wrote:

> I am trying to prepare a matrix, I have a for loop and in this loop I
> increase every number in the matrix by one and make some calculations,
> when I finish my calculations then I need to say fix one number in my
> matrix and make zero the other numbers in the same row. Same
> calculations need to be done again from the beginning however these zero
> values mustn't change. I need to fix these zero values and try to put
> these numbers in quarantine and these numbers should not be affected by
> any calculations. for example I will start with
> s=zeros(5,5)
> I will find s(1,5) should be 1 then I will fix all numbers as 0 in this
> row except 5th column number, s(1,1)=s(1,2)=s(1,3)=s(1,4)=0. Then
> continue my calculations by increasing each number except these 0 values
> by 1, these zeros will never be affected from any calculations? How can
> I do that?


Perhaps something like this?

CanVary = false(5,1);
...
CanVary(5) = true;

s(1,~CanVary) = 0;
...
s(1,CanVary) = s(1,CanVary) + 1;

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us