I = randi([1 50],10,5); cnt = zeros (1,50); for i=1:10 for j=1:5 temp=I(i,j); cnt(temp)=cnt(temp)+1; end end histogram(cnt); --------------------- I=double(imread('cameraman.tif')); Cnv_I=I; [row,col]=size(I); msk=[0 1 0;1 -4 1;0 1 0]; for i=2:row-1 for j=2:col-1 temp=I(i-1:i+1,j-1:j+1); cnv_sum=sum(sum(msk.*temp)); Cnv_I(i,j)=cnv_sum; end end figure, imshow(uint8(I)),title('Original Image'); figure, imshow(Cnv_I),title('Convolved Image'); --------------------------------------------------- load fisheriris.mat; % Generate random data points for demonstration rng(42); % Set random seed for reproducibility num_points = 100; num_clusters = 3; data = rand(num_points, 2); % Initialize cluster centroids randomly initial_centroids = data(randperm(num_points, num_clusters), :); % Number of iterations max_iterations = 100; tolerance = 1e-4; % K-means algorithm centroids = initial_centroids; for iter = 1:max_iterations % Assign data points to nearest centroids distances = pdist2(data, centroids); [~, cluster_ids] = min(distances, [], 2); % Update centroids new_centroids = zeros(num_clusters, 2); for k = 1:num_clusters cluster_points = data(cluster_ids == k, :); new_centroids(k, :) = mean(cluster_points); end % Check for convergence if norm(new_centroids - centroids, 'fro') < tolerance break; end centroids = new_centroids; end % Plot the results figure; scatter(data(:, 1), data(:, 2), [], cluster_ids, 'filled'); hold on; scatter(centroids(:, 1), centroids(:, 2), 100, 'k', 'filled', 'MarkerEdgeColor', 'w'); title('K-means Clustering'); legend('Data Points', 'Cluster Centroids'); hold off;