% Your data
Country = {'Iraq';'Iran';'Syria';'UAE';'Egypt';'Yemen'};
Y1990 = {'0';'700';'500';'350';'0';'800'};
Y1991 = {'550';'600';'730';'440';'600';'660'};
Y1992 = {'670';'500';'900';'870';'700';'260'};
Y1993 = {'200';'400';'550';'640';'0';'770'};
Y1994 = {'220';'610';'490';'0';'0';'0'};
Y1995 = {'400';'730';'550';'850';'560';'890'};
Y1996 = {'350';'440';'110';'490';'300';'980'};
Y1997 = {'270';'370';'560';'0';'660';'770'};
Y1998 = {'0';'800';'0';'900';'0';'880'};
Y1999 = {'420';'410';'890';'740';'0';'330'};
Y2000 = {'920';'710';'810';'660';'450';'0'};
Data = table(Country, Y1990, Y1991, Y1992, Y1993, Y1994, Y1995, Y1996, Y1997, Y1998, Y1999, Y2000);
% Initialize output table
OutputData = table();
% Iterate through each row
for i = 1:size(Data, 1)
% Get the country name
countryName = Data.Country{i};
% Extract the rain data for the current country
rainData = cellfun(@str2double, Data{i, 2:end});
% Find years with zero rain
zeroRainYears = Data.Properties.VariableNames(1 + find(rainData == 0));
% Count of zero rain years
zeroRainCount = numel(zeroRainYears);
% Add a row to the output table
OutputData = [OutputData; table({countryName}, zeroRainCount, {strjoin(zeroRainYears, ', ')}, 'VariableNames', {'Country', 'ZeroRainCount', 'ZeroRainYears'})];
end
% Display the output table
disp(OutputData);
引用格式
Helin Qais (2024). Counting zero rain data (https://www.mathworks.com/matlabcentral/fileexchange/156827-counting-zero-rain-data), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |