calculate the maximum of a series of values ​​in a large matrix

3 visualizaciones (últimos 30 días)
Victoria Pilar Quesada García
Victoria Pilar Quesada García el 21 de Mzo. de 2023
Editada: Dinesh el 29 de Mzo. de 2023
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 comentarios
dpb
dpb el 21 de Mzo. de 2023
Editada: dpb el 22 de Mzo. de 2023
485/24, mod(485,24)
ans = 20.2083
ans = 5
isn't even to be able to assume one row/hour in a day with that dataset.
So, what's the exact content of the file; from whence is one to be able to determine what day/time corresponds to a given element in the array?
dpb
dpb el 23 de Mzo. de 2023
N=485*485, num2str(N/24,'%.3f'), mod(N,24)
N = 235225
ans = '9801.042'
ans = 1
IFF the file happens to be 485 x 485 hourly observations AND
  1. the first element begins at midnight of the first day AND
  2. the data were written sequentially by column, AND
  3. 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...

Iniciar sesión para comentar.

Respuestas (1)

Dinesh
Dinesh el 29 de Mzo. de 2023
Editada: Dinesh el 29 de Mzo. de 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!

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by