Calculate all slopes of arrays in a cell

4 ビュー (過去 30 日間)
Anni Shi
Anni Shi 2022 年 8 月 15 日
回答済み: Image Analyst 2022 年 8 月 16 日
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 件のコメント
David Hill
David Hill 2022 年 8 月 15 日
Attach your data if you can.
Anni Shi
Anni Shi 2022 年 8 月 15 日
Data file is attached. Thank you for the reminder!

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2022 年 8 月 16 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by