Matlab issues with plotting a variable
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a csv file that I would like to take 2 columns from and make them x and y axis. I managed to plot one of the columns however the other column always gives me an error whenever I try to plot with it. I attached the data file below. Here is my code:
intel_cpus=readtable('intel.csv');
C=intel_cpus.("Cores");
E = intel_cpus.("BaseSpeed");
plot(C,'.')
I am trying to get columns D and F as axis of my graph. Thank you for any help!
1 个评论
Mathieu NOE
2021-5-17
hello
I noticed that the csv file as not same number of separators in all lines (separator = comma)
see the result in the table will right shift some fields
this is also obvious when you convert inot xlsx file with comma separator
need some cleaning first ...
采纳的回答
Star Strider
2021-5-17
There are gaps in the ‘Base Speed’ variable, so these need to be detected and the corresponding rows of ‘Cores’ eliminated in order for the vectors to have the same number of elements, as required by plot.
intel_cpus = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/620443/intel%20(2).csv','VariableNamingRule','preserve')
% Q2 = intel_cpus(178:198,:)
C = intel_cpus.('Cores');
E = intel_cpus.('Base Speed');
Lc = cellfun(@(x)~isempty(x), E, 'Unif',0); % Cell Array Of Logical Values
Lv = [Lc{:}]'; % Logical Vector
En = regexp(E,'\d+.\d+','match'); % Get Numeric Data
En = str2double([En{:}]).'; % Extract Numeric Data
figure
plot(C(Lv),En,'.')
grid
xlabel('Cores')
ylabel('Base Speed')
.
7 个评论
Star Strider
2021-5-17
The easiest way to do that would be to use regexp to isolate the core designations, then use some sort of logical comparison or findgroups to get the cores you want, for example —
intel_cpus = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/620443/intel%20(2).csv','VariableNamingRule','preserve')
% Q2 = intel_cpus(178:198,:)
Pc = regexp(intel_cpus.Processor, 'i\d', 'match');
Pn = [Pc{:}]'
idx_i9 = ismember(Pn, 'i9')
% C = intel_cpus.('Cores');
% E = intel_cpus.('Base Speed');
% Lc = cellfun(@(x)~isempty(x), E, 'Unif',0); % Cell Array Of Logical Values
% Lv = [Lc{:}]'; % Logical Vector
%
% En = regexp(E,'\d+.\d+','match'); % Get Numeric Data
% En = str2double([En{:}]).'; % Extract Numeric Data
%
% figure
% plot(C(Lv),En,'.')
% grid
% xlabel('Cores')
% ylabel('Base Speed')
Then use that logical vector (‘idx_i9’ here) similarly to the way I used ‘Lv’ in the plot call, to define the rows of interest. Note that this would likely require combining logical vectors using the and,& function in order that the selected rows or vectors reflect both conditions (and any other logical conditions that might arise from further processing).
.
更多回答(1 个)
Markus
2021-5-17
编辑:Markus
2021-5-17
I think you want to remove the characters after the floating values. You cannot plot the values with the units attached.
While it might not be the cleanest, you could just go for:
D = str2double(replace(intel_cpus.("MaxTurboSpeed"),{' GHz',' MHz'},''));
and
E = str2double(replace(intel_cpus.("BaseSpeed"),{' GHz',' MHz'},''));
F = str2double(replace(intel_cpus.("CacheSize"),{' MB'},''));
Please do remember to add some code to keep the unit info regarding giga and mega.
I assume you are using this for something like an overview, so it should be fine.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!