Using for loop with if condition
24 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
G Suresh
il 4 Feb 2026 alle 10:31
Commentato: Walter Roberson
circa 20 ore fa
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 Commenti
Risposta accettata
Walter Roberson
il 4 Feb 2026 alle 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 Commenti
Walter Roberson
circa 20 ore fa
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
circa 20 ore fa
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!