how do i create a loop that checks checks every column one row at a time in a matrix for a string called "nan" in matlab

main.m
% Sample matrix
matrix = ["hello", "world", "how"; "are", "you", "nan"; "today", "nan", "fine"];

% Get the size of the matrix
[rows, cols] = size(matrix);

% Loop through each column and check for the string "nan" in each row
for i = 1:cols
    for j = 1:rows
        if strcmp(matrix(j, i), "nan")
            disp(['Found "nan" at column ', num2str(i), ', row ', num2str(j)]);
        end
    end
end
404 chars
15 lines

related categories

gistlibby LogSnag