Filter löschen
Filter löschen

Matlab not aligning correct values in excel with the correct x value?

1 Ansicht (letzte 30 Tage)
Olivia Wycklendt
Olivia Wycklendt am 12 Okt. 2017
Kommentiert: Jan am 12 Okt. 2017

I tried making a boxplot for data that involves different varieties of plants. The x values are the different types of plants used, and the y values is a given number in an excel sheet. I created a boxplot and it appears right, however the x values do not correlate with the correct y values. Is there any way I can fix this? The excel sheet appears to be correct, along with the other sheets (African rice won't merge with the Maize data, however). The code is provided below:

% Plot variability in s* from crop drought experiments.
clear all; close all; clc
% Load data
load FTSW_Thresholds.mat
% merge Millet with Pearl Millet and the four grasses
x=strcmp(Crop,'Pearl Millet');
Crop(x)={'Millet'};
x=strcmp(Crop,'bermudagrass');
Crop(x)={'Grass'};
x=strcmp(Crop,'zoysiagrass');
Crop(x)={'Grass'};
x=strcmp(Crop,'Seashore Paspalum');
Crop(x)={'Grass'};
x=strcmp(Crop,'Turfgrass');
Crop(x)={'Grass'};
x=strcmp(Crop,'Grain');
Crop(x)={'Millet'};
x=strcmp(Crop,'African Rice');
Crop(x)={'Maize'};  
%merge other similar crops
x=strcmp(Crop,'Black Gram');
Crop(x)={'Soybean'};
x=strcmp(Crop,'Black gram');
Crop(x)={'Soybean'};
x=strcmp(Crop,'Groundnut');
Crop(x)={'Peanut'};
x=strcmp(Crop,'Corn');
Crop(x)={'Maize'};
x=strcmp(Crop,'Cowpea');
Crop(x)={'Pigeon Pea'};
x=strcmp(Crop,'A. Rubrum');
Crop(x)={'Red Maple'};
x=strcmp(Crop,'R. Pseudoacacia');
Crop(x)={'Black Locust Tree'};
x=strcmp(Crop,'Ibex Aquifolium');
Crop(x)={'Holly Tree'};
x=strcmp(Crop,'Thuja Plicata');
Crop(x)={'Pacific Red Cedar'};
x=strcmp(Crop,'Hibiscus sp.');
Crop(x)={'Hibiscus'};
crop_name=unique(Crop);
g=zeros(length(crop_name),length(Crop));
for i=1:length(crop_name)      
    g(i,:)=strcmp(Crop,crop_name(i));      
end
boxplot(FTSW_threshold,g','labels',crop_name,'labelorientation','inline')
set(gcf,'Color',[1 1 1])
set(gca,'FontSize',14)
ylabel('Threshold for transpiration decline')
ylim([0 1])
  2 Kommentare
Image Analyst
Image Analyst am 12 Okt. 2017
It sure would have made it easier to answer if you had included a screenshot and attached 'FTSW_Thresholds.mat' so we could have run your code ourselves.
Jan
Jan am 12 Okt. 2017
Which Excel sheet? The code looks really confusing. Perhaps you want to create a table for the translations e.g. as a cell string matrix instead. Then the replacements can be performed in a loop.
The description of the problem is very vague only: "the x values do not correlate with the correct y values". How could we guess, what is correct and what is not? We cannot even run your code due to the missing inputs.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by