How to remove a value from matrix with same values in different positon?

Hi everyone. I have 3x3 matrix of
T = [7,8,8 ; 6,4,10 ; 12,8,7]
I want to remove seven at first row and first column and not the other 7 in the last row and last column. How to remove it and same will apply for 8 also. I used indexing as T(T==7) = NaN; but it removes both values as the condition implies. Kindly please help with this. Thanks in advance.

6 Comments

Unless there some other logical condition to use other than the row, you simply use the row index in the expression...
T(T(1,:)==7)=nan;
etc., ...
Hello dpb, Thanks for your reply.
T(T(1,:)==7) = nan; does'nt help. Is ther any other technique that I can use.
Note: I am using this in a for loop. So for every iteration the value will be changed so I can't fix the row value as same. Hope you understand my problem.
No, we don't.
The above works for the Q? as asked; you'll have to illustrate the actual problem if that isn't the real question.
If it's simply iterating over a row index, there's nothing to prevent substituting the loop index (or any other) variable for the constant in the indexing expression.
But, as noted above, you have to have some codable logic by which to decide what row is to be operated on (and what value to substitute, etc., ...).
Matlab is general coding language; you can do virtually anything you can imagine but you first must be able to define what that something is...which isn't clear for the general case here.
I am extreamly sorry for the incovinience I'll attach the actual problem in this comment.
Mc = [1,3,2; 2,1,3; 1,2,3]; % Machine Number
PT = [7,8,10; 6,4,12; 8,8,7]; % Processing Time
Stime = zeros(3,3); %Start time
Etime = zeros(3,3); %End Time
T = zeros(3,3); %Temporary Matrix
for i = 1:3
for j = 1:3
machineIndex = Mc(i,j);
minV = min(PT(Mc==i));
Stime(i,j) = T(i,j);
for k = 1:n
if Stime(i,j) + minV >= T(i,k)
T(i,k) = Stime(i,j) + minV;
end
end
for k = 1:m
if Stime(i,j) + minV >= T(k,machineIndex)
T(k,machineIndex) = Stime(i,j) + minV;
end
end
Etime(i,j) = Stime(i,j)+ minV;
PT(PT==minV) = NaN;
end
end
I just want to schedule the minimum job first and next minimum job according to Machine Number. The processing time of Jobs are given in PT. I think this explains. And sorry for not explaining clearly.
What are n, m in the two loop limit expressions intended to be? They're undefined here.
"...schedule the minimum job first and next minimum job ..."
Why isn't the order just sort(minV) then?
T=sort(minV);
After that, ETime and STime will just be
Etime=cumsum(T);
Stime=[0;Etime(1:2)];
it would seem.

Sign in to comment.

 Accepted Answer

You can obtain the indices of the first occurrence of each value in a matrix using the ‘unique’ function. Refer to the following link for details on how to use ‘unique’:
After you obtain the indices you can find the indices which have duplicate values by using the ‘ismember’ function. Refer to the link below:
Refer to the code below to obtain your functionality:
T = [7,8,8 ; 6,4,10 ; 12,8,7];
[C, ia] = unique(T, 'first');
x = 1:numel(T);
[lic, lob] = ismember(x, ia);
T(x(~lic)) = NaN;

More Answers (0)

Categories

Find more on MATLAB Mobile in Help Center and File Exchange

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!