Hi everyone I have a dataset of about 2 years with 1min timestep, but there are gaps in the dates. Any idea how I can calculate the 30min averages? My dataset looks like this: date value 09/01/2015 00:03 2.5 09/01/2015 00:04 2.8 09/01/2015 00:11 3.1 09/01/2015 00:15 2.3 Thank you
MATLAB: How to calculate 30-min averages from 1-min data with gaps
30min averages
Related Solutions
Stelios, since you didn't provide me with the original image I had to take a screenshot and try to fix it up in Photoshop. Then I thresholded, blurred, rethresholded, scanned for the top row, and overlaid it on the original image. Code is below. Let me know if you like it.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;%===============================================================================
% Read in gray scale demo image.
folder = pwd; % Determine where demo folder is (works with all versions).
baseFileName = 'sofar.jpg';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)if numberOfColorChannels > 1 % It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 1); % Take red channel.
else grayImage = rgbImage; % It's already gray scale.
end% Now it's gray scale with range of 0 to 255.
% Display the image.
subplot(4, 1, 1);imshow(grayImage, []);title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');axis('on', 'image');hp = impixelinfo();%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')drawnow;% Binarize the image
binaryImage = grayImage >= 3;% Extract the largest blob only
binaryImage = bwareafilt(binaryImage, 1);% Fill holes
binaryImage = imfill(binaryImage, 'holes');% Display the image.subplot(4, 1, 2);imshow(binaryImage, []);title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');axis('on', 'image');hp = impixelinfo();drawnow;% Blur the image
windowWidth = 25;blurredImage = conv2(double(binaryImage), ones(windowWidth)/windowWidth^2, 'same');% Threshold again.
binaryImage = blurredImage > 0.5;% Display the image.subplot(4, 1, 3);imshow(binaryImage, []);title('Smoothed Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');axis('on', 'image');hp = impixelinfo();drawnow;% Scan the image looking for the top most pixel.
topRows = rows * ones(1, columns); % Preallocate.
for col = 1 : columns thisTopRow = find(binaryImage(:, col), 1, 'first'); if ~isempty(thisTopRow) topRows(col) = thisTopRow; endend% Display the image.subplot(4, 1, 4);imshow(grayImage, []);title('Original Image with top rows overlaid', 'FontSize', fontSize, 'Interpreter', 'None');axis('on', 'image');hp = impixelinfo();% Show top line over it.
hold on;plot(topRows, 'r-', 'LineWidth', 2);
[v,idx] = min(A,[],1)out = [v;idx;1:size(A,2)]
or
absolute min
[v,I] = min(A(:));[ir,jc] = ind2sub(size(A),I);out = [v,ir,jc];
Best Answer