Calculate all slopes of arrays in a cell

4 vues (au cours des 30 derniers jours)
Anni Shi
Anni Shi le 15 Août 2022
Hello,
I generated a cell structure with 6 2100*4 arrays.
I want to calculate the slope of the first(x) and the second column (y) of each array in the cell.
Is there any way to operate individual element in a cell and return the list of outputs?
Thank you?
  3 commentaires
David Hill
David Hill le 15 Août 2022
Attach your data if you can.
Anni Shi
Anni Shi le 15 Août 2022
Data file is attached. Thank you for the reminder!

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 16 Août 2022
Try this:
% Demo by Image Analyst
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
s = load('test_data.mat')
Allmsd = s.Allmsd
[rows, columns] = size(Allmsd)
slopes = zeros(rows, 1);
subplot(2, 1, 1);
for k=1:numel(Allmsd)
thisArray = Allmsd{k};
x = thisArray(:, 1);
y = thisArray(:, 2);
% Get rid of nans.
badIndexes = isnan(x) | isnan(y);
x(badIndexes) = [];
y(badIndexes) = [];
plot(x, y, '-', 'LineWidth', 2);
grid on;
hold on;
coefficients = polyfit(x, y, 1)
slopes(k) = coefficients(1)
end
legend
title('Individual Curves', 'FontSize', fontSize)
% Plot slopes
subplot(2, 1, 2);
bar(slopes)
grid on;
title('Slopes', 'FontSize', fontSize)

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by