calculate the maximum of a series of values in a large matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have this but it only applies to data with one row and many columns and I want to apply the same but to a matrix that has 485 rows and the same columns
clear all;close all
load("date 1*552262.mat")
data=sshobscorr
% determine total number of days of data
numDays = length(data)/24;
% reshape your temperature data so that you have a column for each day, with a row for each hour in the day
Tdata = reshape(data,24,numDays)
% calculate your min and max for each day
dailyMin = min(Tdata);
dailyMax = max(Tdata);
2 commentaires
dpb
le 23 Mar 2023
N=485*485, num2str(N/24,'%.3f'), mod(N,24)
IFF the file happens to be 485 x 485 hourly observations AND
- the first element begins at midnight of the first day AND
- the data were written sequentially by column, AND
- you throw away the one odd element at the end,
then and only then
...
data=data(:); % create long column vector of total number
data=data(1:end-mod(N,24)); % keep even multiple of 24
data=reshape(data,24,[]); % and now can reshape
dailyMinMax=[min(data);max(data)]; % put in an array for grins...
A zillion assumptions made, but with no other information to go on...
Réponses (1)
Dinesh
le 29 Mar 2023
Modifié(e) : Dinesh
le 29 Mar 2023
Hi Victoria!
As per my understanding, Data is a 1D array of hourly temperatures. Assuming the same for the array with 485 rows and several columns, say ‘n’. Then we have 485 * n number of hours in total. A straightforward way to solve the problem is the following.
total_hours = 485 * n; % calculate total hours
days = total / 24; % get total days
remainder = mod(total,24); % number of hours that last day has
Total number of hours might not be multiple of 24. So, on last day we will not have complete information.Thus, we will calculate min and max separately for the last day.
data = data(:) % convert to 1D array
if remainder ~= 0 %if last day information has 5 hours, then find min and max of those 5 hours
minmax = [min(data(total_hours-remainder:end)), max(data(total_hours - remainder:end))]
end
data = data(1:total_hours - remainder)
data = reshape(data, 24, [])
dailyMin = [min(data), minmax(0)]
dailyMax = [max(data), minmax(1)]
If you do not want to convert the 2D array, then simply iterate over the rows.
for i= 1:485
row = data(i,:)
% if columns n % 24 ~= 0 then take care about calculating min and max
end
Hope this helps,
Thank you!
0 commentaires
Voir également
Catégories
En savoir plus sur Calendar dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!