how to write for loop to write in my data set if there is a signal
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I wirte a for loop so it will wirte a 1 into 500 cells prior to their already being a 1 into my data set. I have 99 data sets.
2 Kommentare
Dyuman Joshi
am 3 Dez. 2022
It's not clear what you want.
Show an example, what you have and what you want to obtain.
Antworten (1)
Nirupama Nagarathinam
am 22 Mai 2023
Your question is not very clear. But with the little understnading I got from the question, I guess you want to replace "0" with "1" using a for loop.
Find below a sample code for the same :
A = [0 0; 2 3]; %sample matrix
[r,c]=size(A); %obtaining the number of rows and columns of the matrix
for i=1:r %Iterating through all rows of matrix A
for j=1:c %Iterating through all columns of matrix A
if A(i,j) == 0 %Checking if the element in matrix A has value 0
A(i,j) = 1; %Setting the value to 1
end
end
end
disp(A)
If you want to do this change for 99 different data sets, then you can convert and save this code to a function as follows:
function replacingZero(input_dataset)
[r,c]=size(input_dataset); %obtaining the number of rows and columns of the dataset
for i=1:r %Iterating through all rows of dataset
for j=1:c %Iterating through all columns of dataset
if input_dataset(i,j) == 0 %Checking if the element in dataset has value 0
input_dataset(i,j) = 1; %Setting the value to 1
end
end
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!