Calculate all slopes of arrays in a cell

4 visualizaciones (últimos 30 días)
Anni Shi
Anni Shi el 15 de Ag. de 2022
Respondida: Image Analyst el 16 de Ag. de 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 comentarios
David Hill
David Hill el 15 de Ag. de 2022
Attach your data if you can.
Anni Shi
Anni Shi el 15 de Ag. de 2022
Data file is attached. Thank you for the reminder!

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 16 de Ag. de 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)

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by