How to create a hysteresis loop
113 views (last 30 days)
Show older comments
I am very new to coding and I want to understand how to generate a hysteresis loop for blood vessels. This work was done in mice but the ones I see on MatLab answer primarily have to do with magnetism and I am unsure how to tailor my data to fit the different equations/codes.
Below is the code I wrote which essentially plots my data set but it does not generate a loop per se.
lumenWT = (Old.WT_2283)
pressureWT = (Old.Pressure);
x = floor(length(lumenWT)/2);
x1 = lumenWT(1:x);
x2 = lumenWT(x:end);
y1 = pressureWT(1:x);
y2 = pressureWT(x:end);
figure
L1 = plot(y1,x1,'-k',LineWidth=2);
hold on
L2 = plot(y2,x2,'-k',LineWidth=2);
legend([L1 L2 L3 L4], ...
'WT Loading','WT Unloading','Location','southeast');
ylabel('Lumen diameter (microns)')
xlabel('Pressure(mmHg)')
title("Old")
grid on
An answer from a few years ago generate this script which is what I am hoping to recreate but I have not been successful. :
X = [-3:.2:3 3:-.2:-3];
Y = [tanh(X(1:length(X)/2)-1) tanh(X(length(X)/2+1:end)+1)];
patch(X,Y,[.5 1 .5]); hold on
quiver(X(1:end-1),Y(1:end-1),diff(X),diff(Y),0);
I am kindly asking for some suggestions or some direction
Answers (2)
Sulaymon Eshkabilov
on 3 Jan 2023
Edited: Sulaymon Eshkabilov
on 3 Jan 2023
clearvars
Old = readtable('Old.xlsx');
lumenWT = (Old.WT_2283) ;
pressureWT = (Old.Pressure);
x = floor(length(lumenWT)/2);
x1 = lumenWT(1:x);
x2 = lumenWT(x:end);
y1 = pressureWT(1:x);
y2 = pressureWT(x:end);
x2 = rmmissing(x2);
y2 = rmmissing(y2);
figure(1)
L1 = plot(y1,x1,'-k','LineWidth', 2);
hold on
L2 = plot(y2,x2,'-k','LineWidth',2);
legend([L1 L2], ...
'WT Loading','WT Unloading','Location','southeast');
ylabel('Lumen diameter (microns)')
xlabel('Pressure(mmHg)')
title("Old")
grid on
X = [x1; x2; -1*x1; -1*x2];
Y= [y1; y2; -1*y1; -1*y2];
patch(Y,X,[.5 1 .5]); hold on
quiver(Y(1:end-1),X(1:end-1),diff(Y),diff(X),0);
William Rose
on 3 Jan 2023
[I moved my code to the "Answer" section, which is where I should have posted it initially.]
I relaize that you have raised and then lowered the pressure inside a blood vessel. YOu have measured the diameter as a funciton of pressure. You did the experiment in three specimens.
There is one rows on NaNs in the data, which we will remove.
Here is code to plot the pressure-diameter loops.
data=xlsread('Old.xlsx');
pres=data(:,1); %column 1 = pressure
diam=data(:,2:end); %columns 2-4=diameter
[~,cols]=size(diam);
pres=pres(~isnan(pres)); %remove rows with NaN
diam=diam(~isnan(diam)); %remove rows with NaN
diam=reshape(diam,[],cols); %reshape diam to have 3 columns
[rows,~]=size(diam);
rm=rows/2; %middle row number
figure;
plot(pres(1:rm),diam(1:rm,1),'-r','linewidth',2); hold on
plot(pres(rm+1:end),diam(rm+1:end,1),'--r','linewidth',2); hold on
plot(pres(1:rm),diam(1:rm,2),'-g','linewidth',2); hold on
plot(pres(rm+1:end),diam(rm+1:end,2),'--g','linewidth',2); hold on
plot(pres(1:rm),diam(1:rm,3),'-b','linewidth',2); hold on
plot(pres(rm+1:end),diam(rm+1:end,3),'--b','linewidth',2);
xlabel('Pressure (mmHg'); ylabel('Diameter (\mum)');
grid on; title('Pressure versus Diameter')
legend('WT2272 up','WT2272 down','WT2283 up','WT2283 down',...
'WT2271 up','WT2271 down','location','southeast');
Good luck.
0 Comments
See Also
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!