필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Pauline
Pauline 2022년 12월 3일
답변: Nirupama Nagarathinam 2023년 5월 22일
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
Dyuman Joshi
Dyuman Joshi 2022년 12월 3일
It's not clear what you want.
Show an example, what you have and what you want to obtain.
Pauline
Pauline 2022년 12월 8일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Nirupama Nagarathinam
Nirupama Nagarathinam 2023년 5월 22일
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

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by