calculate the maximum of a series of values in a large matrix
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2023-3-23
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...
回答(1 个)
Dinesh
2023-3-29
编辑:Dinesh
2023-3-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!