how to write for loop to write in my data set if there is a signal
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 3 Dic 2022
It's not clear what you want.
Show an example, what you have and what you want to obtain.
Risposte (1)
Nirupama Nagarathinam
il 22 Mag 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 Commenti
Vedere anche
Categorie
Scopri di più su Database Toolbox 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!