Using for loop with if condition
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
G Suresh
le 4 Fév 2026 à 10:31
Commenté : Walter Roberson
il y a environ 18 heures
Respectd Team,
I am looking solution for genration of data load by text.
My problem in simple manner, We have 14 floor building with 20 rooms in each floor, I have to write a code for once the person is enter into the room 1st floor 101 and remaining values in corresponding top floors should be zer (ex :201,301....1401) and if the person enter into 2room no 415 (4 floor & no 15) than correpsonding values in 115,215,315,515....1415 should be zero.
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Fév 2026 à 11:37
MaxFloors = 14;
MaxRooms = 20;
BuildingData = zeros(MaxFloors, MaxRooms);
FloorRoomData = [1 1; 4 15];
for Row = 1 : height(FloorRoomData);
FloorIndex = FloorRoomData(Row, 1);
RoomIndex = FloorRoomData(Row, 2);
BuildingData(:, RoomIndex) = 0;
BuildingData(FloorIndex, RoomIndex) = 1;
end
BuildingData
3 commentaires
Walter Roberson
il y a environ 5 heures
for i=1:z
for j=1:l
t(i,j)=M(i,j)
end
end
That can be more easily done as
t = M(1:z, 1:l);
Walter Roberson
il y a environ 4 heures
You have presented code with few useful comments. Under the circumstances, we must understand that the defined requirements of the code are identical to the current implementation of the code, that the purpose of the code is to compute exactly whatever it presently calculates. Therefore, you are incorrect that the code is not printing as per your requirement, since your requirement is defined by exactly what it prints.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!