Filter löschen
Filter löschen

how to write for loop to write in my data set if there is a signal

2 Ansichten (letzte 30 Tage)
Pauline
Pauline am 3 Dez. 2022
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
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.
Pauline
Pauline am 8 Dez. 2022
I want there to be a one instad of a 0 in collum 6. How do I write a do loop fo all data sets?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Nirupama Nagarathinam
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)
1 1 2 3
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

Community Treasure Hunt

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

Start Hunting!

Translated by