필터 지우기
필터 지우기

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 CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by