how to write for loop to write in my data set if there is a signal
2 ビュー (過去 30 日間)
古いコメントを表示
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
2022 年 12 月 3 日
It's not clear what you want.
Show an example, what you have and what you want to obtain.
回答 (1 件)
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)
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!