필터 지우기
필터 지우기

Enumeration of classes in inheritance

조회 수: 2 (최근 30일)
Stergios Verros
Stergios Verros 2020년 1월 23일
편집: per isakson 2020년 1월 26일
Dear all,
I have 2 files with two column vectors each from which I would like to plot each file collumns versus each other. Bellow you can find my code so far:
classdef Data_load
properties
Column1
Column2
end
methods
function obj = Data_load(Data)
if nargin > 0
obj.Column1 = Data(:,1);
obj.Column2 = Data(:,2);
end
end
end
end
classdef PlotsClass < Data_load
methods
function plot_Column1_vs_Column2(obj)
figure(1)
plot(obj.Column1,obj.Collumn2);
end
end
end
First_file = PlotsClass(First_file_Data)
First_file.plot_Column1_vs_Column2()
Second_file = PlotsClass(Second_file_Data)
Second_file.plot_Column1_vs_Column2()
Now, I would like to plot the collumns of both files in one plot. How is it possbile to create a subclass that iterates through the data of the objects of the PlotsClass? So far I just use a static method in a seperated class but I would like to know if there is a better way of doing it.
Stergios

채택된 답변

per isakson
per isakson 2020년 1월 26일
편집: per isakson 2020년 1월 26일
I might neither fully have understood your code nor the title of the question. Nevertheless, I think this is a better approach.
%%
data(2) = Data_load( Second_file_Data );
data(1) = Data_load( First_file_Data );
%%
pc = PlotsClass;
pc.plot_Column1_vs_Column2( data )
where
classdef Data_load
properties
Column1
Column2
end
methods
function obj = Data_load(Data)
if nargin > 0
obj.Column1 = Data(:,1);
obj.Column2 = Data(:,2);
end
end
end
end
and
classdef PlotsClass < handle
methods
function plot_Column1_vs_Column2( this, data_obj )
figure(1)
hold on
for jj = 1 : length( data_obj )
plot( data_obj(jj).Column1, data_obj(jj).Collumn2 );
end
hold off
end
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Enumerations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by