Hi,
The 'bar' function in MATLAB requires unique XData values for the bars. When the week numbers are reset after every 52 weeks, this results in duplicate XData values. The workaround can be to create a new set of labels for the x-axis that includes the year and week number.
Here is how to implement this:
% Assuming 'workload' is your vector containing workload data
workload = rand(1, 3*52*2); % replace this with the actual data
% Create a vector for weeks
weeks = 1:length(workload);
% Calculate year and week number
yearNum = ceil(weeks/52);
weekNum = mod(weeks-1, 52) + 1;
% Create new labels
newLabels = arrayfun(@(y, w) sprintf('y%dw%d', y, w), yearNum, weekNum, 'UniformOutput', false);
% Plot the data
bar(weeks, workload);
xlabel('Week');
ylabel('Workload [worker per week]');
% Adjust x-axis tick labels
set(gca, 'XTick', 1:1:length(weeks)); % set xticks for each week
set(gca, 'XTickLabel', newLabels); % apply new labels
This will give an x-axis that displays labels in the format ‘y1w1’, ‘y1w2’, …, ‘y2w1’, ‘y2w2’, … for each week.
I hope this helps!