My matlab code is giving me this error "Too many outputs requested". If someone can help me solve this?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello, My code is as follows:
%Create a vector with date and time
c_forecast = clock
%Put the integer vector values in strings
year_forecast = int2str(c_forecast(1));
month_forecast = int2str(c_forecast(2));
day_forecast = int2str(c_forecast(3));
hours_forecast = int2str(c_forecast(4));
%Check if the month string has 1 or 2 digits (this is important for the
%comparison of the julian date string)
if size(month_forecast) == 1
month_forecast = strcat('0',month_forecast);
end
%check if the day string has 1 or 2 digits.
if size(day_forecast) == 1
day_forecast = strcat('0',day_forecast);
%month = strcat('0',day);
end
%nextday=[day add];
%check if the hour string has 1 or 2 digits.
if size(hours_forecast) == 1
hours_forecast = strcat('0',hours_forecast);
end
% To be searched in xml file
search_forecast=strcat(year_forecast,'-',month_forecast,'-',day_forecast,'T',hours_forecast,':00:00Z');
%%Weather Data
% Retrieving Cloud cover information from URL
%cloud cover
xdom = xmlread('http://api.met.no/weatherapi/locationforecast/1.9/?lat=53.05;lon=4.8;msl=1');
cloudtags = xdom.getElementsByTagName('cloudiness');
cloudiness_forecast = cell(cloudtags.getLength, 2);
for item = 1 : cloudtags.getLength
cloudtag = cloudtags.item(item - 1);
timetag = cloudtag.getParentNode.getParentNode;
cloudiness_forecast{item, 1} = char(timetag.getAttribute('from'));
cloudiness_forecast{item, 2} = str2double(cloudtag.getAttribute('percent'));
end
cloudiness_forecast;
matchrow = strcmp(cloudiness_forecast(:, 1), search_forecast);
cloud_forecast = cloudiness_forecast{matchrow, 2};
When I try to run it, it gives me the following error:
Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.
Error in PowerCalculation cloud = cloudiness{matchrow, 2};
Can someone help me solve this problem. Thank you.
댓글 수: 3
Walter Roberson
2024년 10월 23일
I suspect that your function shrinkImage is generating output to the display.
Fiyinfoluwa
2024년 10월 23일
@Walter Roberson Please take a look at the function:
function newBlock = shrinkImage(blockStruct)
% shrinkImage extracts the block data from the input structure
% and finds its median and returns that scalar as the output
% extract the data field of the structure blockStruct
block = blockStruct.data;
% calculate the median of the data field and save to newBlock
newBlock = median(block, "all");
end
채택된 답변
Mohammad Abouali
2015년 4월 5일
편집: Mohammad Abouali
2015년 4월 5일
Don't know why cloud = cloudiness{matchrow, 2}; is causing too many output request error. Are you sure the error is for that line?
On the side note: If you want to have month 6 to be represented as 06 you can also use the following code:
month_forecast=sprintf('%0.2d',c_forecast(2))
The same goes for day. This is much more readable than those if-clauses.
Or you can rewrite the entire top part of your code as:
search_forecast=sprintf('%d-%0.2d-%0.2dT%0.2d:00:00:Z',c_forecast(1:4))
댓글 수: 2
Mohammad Abouali
2015년 4월 5일
The problem is that all elements in matchrow are false. Meaning nothing matched the time string that you are looking for.
So change the code to check if there are any matching rows. Here is how the code changed:
%Create a vector with date and time
c_forecast = clock;
% To be searched in xml file
search_forecast=sprintf('%d-%0.2d-%0.2dT%0.2d:00:00:Z',c_forecast(1:4));
2015-04-15T12:00:00Z
%%Weather Data
% Retrieving Cloud cover information from URL
%cloud cover
xdom = xmlread('http://api.met.no/weatherapi/locationforecast/1.9/?lat=53.05;lon=4.8;msl=1');
cloudtags = xdom.getElementsByTagName('cloudiness');
cloudiness_forecast = cell(cloudtags.getLength, 2);
for item = 1 : cloudtags.getLength
cloudtag = cloudtags.item(item - 1);
timetag = cloudtag.getParentNode.getParentNode;
cloudiness_forecast{item, 1} = char(timetag.getAttribute('from'));
cloudiness_forecast{item, 2} = str2double(cloudtag.getAttribute('percent'));
end
matchrow = strcmp(cloudiness_forecast(:, 1), search_forecast);
if (any(matchrow))
cloud_forecast = cloudiness_forecast{matchrow, 2};
else
disp('WARNING: Nothing matched.')
end
추가 답변 (1개)
Fiyinfoluwa
2024년 10월 23일
Please take a look at the shrinkImage:
function newBlock = shrinkImage(blockStruct)
% shrinkImage extracts the block data from the input structure
% and finds its median and returns that scalar as the output
% extract the data field of the structure blockStruct
block = blockStruct.data;
% calculate the median of the data field and save to newBlock
newBlock = median(block, "all");
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!