Hi,
How can i create a subplot in matlab with my diagram? (2 Columns and 2 Rows) -> See picture:
Here is my code:
%deploytool
%Datei heisst "Testbeispiel_Harald"
%Der Readtable muss im in D:\work\matlab -> Verzeichnis sein
clc % löscht den Bildschirm
clear all % löscht alle Variablen
%*************************************************************************
%Hier wird die Matrix eingelesen.
%Klassenbreite - Anzahl Klassen - Startpunkt
%2 6 10
%2 8 0
%Jetzt kommt das wirkliche Daten
%x-Wert - y-Wert - Häufigkeit
%12 0 10
%14 0 30
%16 0 54
%18 0 51
%20 0 35
%22 0 12
%14 2 25
%16 2 35
%*************************************************************************%Als Input wünsche ich mir den linken unteren Punkt!!!!
%Einlesen der Daten
%Input_Matrix = textread('Testbeispiel_RainflowX.txt')
Input_Matrix=[2 6 10 ;2 8 0;12 0 10;14 0 30;16 0 54;18 0 51;20 0 35;22 0 12;14 2 25;16 2 35]%Bestimmung der Größe der Matrix die als .txt eingelesen wird
[zeilen,spalten]=size(Input_Matrix)%analysiert die grösse der eingelesenen txt datei
%***********Auslesen spezifischer Daten der Matrix"*********************************
Haeufigkeit=Input_Matrix(3:zeilen,3)%(:,3)%gesamte dritte Spalte (exkl. die ersten 2 Zeilen)
ycord=Input_Matrix(3:zeilen,2)%gesamte x-Koordianten (exkl. die ersten 2 Zeilen)
xcord=Input_Matrix(3:zeilen,1)%gesamte y-Koordinaten (exkl. die ersten 2 Zeilen)
x_Klassenbreite=Input_Matrix(1,1) %Wie breit ist die Klasse in x
y_Klassenbreite=Input_Matrix(2,1) %Wie breit ist die Klasse in y
x_Klassen=Input_Matrix(1,2) %Klassenanzahl x?
y_Klassen=Input_Matrix(2,2) %Klassenanzahl y?
x_Start=Input_Matrix(1,3) %KS Startwert in x?
y_Start=Input_Matrix(2,3) %KS Startwert in y?
%************Berechnungen für die Achsendarstellungen**********************
x_Achse_Start=x_Start; %Startpunkt auf x-Achse
y_Achse_Start=y_Start; %Startpunkt auf x-Achsex_Achse_Ende= x_Klassen * x_Klassenbreite+x_Achse_Start %EndWert auf der x-Achse
y_Achse_Ende= y_Klassen * y_Klassenbreite+y_Achse_Start %%EndWert auf der y-Achse
n=10; % höchst zulässige Teilung
if x_Klassen > nx_Teilung = n;elsex_Teilung = x_Klassen;endif y_Klassen > ny_Teilung = n;elsey_Teilung = y_Klassen;end%x_Achse_thicks = (x_Achse_Ende-x_Achse_Start)/10 %x-Achse Teilung
%y_Achse_thicks = (y_Achse_Ende)/10 %x-Achse Teilung
x_Achse_thicks1 = round(linspace(x_Achse_Start,x_Achse_Ende,x_Teilung))y_Achse_thicks1 = round(linspace(y_Achse_Start,y_Achse_Ende,y_Teilung))%figure;
figure1 = figure('Color',[1 0.968627452850342 0.921568632125854]);%Punkte_Matrix => Matrix deren Inhalt die Koordinaten aller Eckpunkte der Rechtecke hat
%Größe => (x Zeilen/ 2 Spalten)
%Benötigte Größe der Punkte_Matrix definieren bzw. alle Werte mit Null initalisieren:
Anzahl_Zeilen_Punkte_Matrix=(zeilen-2)*4;Anzahl_Spalten_Punkte_Matrix=2;%Fixwert 2 Spalten
Punkte_Matrix = zeros(Anzahl_Zeilen_Punkte_Matrix,Anzahl_Spalten_Punkte_Matrix);Connections = reshape(1:Anzahl_Zeilen_Punkte_Matrix,4,[])';%Erzeugt eine Matrix für die
%korrekte Verbindung der Rechtecks-Punkte
value=length(ycord);%Punkte_Matrix mit den Startwerten initalisieren
%X Werte
x=1;for i = 1:value Punkte_Matrix(x,1)=xcord(i); x=x+4end%Punkte_Matrix mit den Startwerten initalisieren%y Werte
x=1;for i = 1:value Punkte_Matrix(x,2)=ycord(i); x=x+4end%Punkte_Matrix mit Punkt2 befüllen
%y Wertex=2;for i = 1:value Punkte_Matrix(x,1)=xcord(i)+x_Klassenbreite; x=x+4endx=2;for i = 1:value Punkte_Matrix(x,2)=ycord(i); x=x+4end%Punkte_Matrix mit Punkt3 befüllen
%y Wertex=3;for i = 1:value Punkte_Matrix(x,1)=xcord(i)+x_Klassenbreite; x=x+4endx=3;for i = 1:value Punkte_Matrix(x,2)=ycord(i)+y_Klassenbreite; x=x+4end%Punkte_Matrix mit Punkt4befüllen
%y Wertex=4;for i = 1:value Punkte_Matrix(x,1)=xcord(i); x=x+4endx=4;for i = 1:value Punkte_Matrix(x,2)=ycord(i)+y_Klassenbreite; x=x+4endpatch('Faces',Connections,'Vertices',Punkte_Matrix,'FaceVertexCData',Haeufigkeit,'FaceColor','flat','EdgeColor','none') %Befehl fürs "zeichnen"
colormap(jet)%figure1 = figure('Color',[1 0.968627452850342 0.921568632125854]);
label_colorbar=colorbarylabel(label_colorbar,'cycles')[maxValue, rowIdx] = max(Haeufigkeit(:,1),[],1)caxis([0,maxValue]) % setzt die color limits
title('Harald will keine Überschrift Platzhalter','FontSize',14);% Create title
xlabel('Mean Value [MPa]','FontWeight','bold');% Create label
ylabel('Amplitude [MPa]','FontWeight','bold');% Create labellegend('Legende brauchen wir auch keine');axis([x_Achse_Start x_Achse_Ende 0 y_Achse_Ende])grid offset(gca,'XTick',x_Achse_thicks1)set(gca,'YTick',y_Achse_thicks1)set(gca,'XGrid','off','YGrid','off','ZGrid','off'); %Raster abschalten
matlab2tikz('Testbeispiel_Harald.tikz', 'height', '\figureheight', 'width', '\figurewidth');%matlab2tikz('Testbeispiel_Harald.tikz', 'height', '\figureheight', 'width', '\figurewidth');
%Test3=matlab2tikz('Testbeispiel_Harald.tex');
%gca.XTickLabelRotation = 45; % bei bedarf
%gca.YTickLabelRotation = 45; % bei bedarf
%set(gca,'YTickLabel',{''})
%set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
%set(gca, 'XTickMode', 'manual', 'XTick', Ticks, 'xlim', [0,20]);
It does not matter if my diagram -> Plot1 – Plot6 is always the same. Should is use a function for it? A loop? I can solve this problem easily in latex but not in matlab cause I am a beginner. thank you in advance.
Best Answer