ClipAndTry

版本 1.0.0 (178.3 KB) 作者: covao
Auto-run MATLAB code from clipboard via ChatGPT
0.0 次下载
更新时间 2024/7/12

ClipAndTry_MAT

View ClipAndTry on File Exchange

When MATLAB function code generated by an LLM like ChatGPT is copied to the clipboard, it automatically runs. If the first line is function(), it executes the function. If it is a MATLAB System class, it creates a Simulink block.

MATLAB commands that download and open a demo program

mkdir('./ClipAndTry_demo');
cd('./ClipAndTry_demo');
websave('ClipAndTry.m','https://raw.githubusercontent.com/covao/ClipAndTry_MAT/main/ClipAndTry.m');
websave('ClipAndTryDemo.m','https://raw.githubusercontent.com/covao/ClipAndTry_MAT/main/ClipAndTryDemo.m');
ClipAndTryDemo;

Prompt Example 1: Create MATLAB function

# Create the following MATLAB function
- Function name: plot_test
- Plot an example using meshgrid()

ChatGPT4-o Results

function plot_test()
    % Create a range of values for x and y
    [x, y] = meshgrid(-10:0.5:10, -10:0.5:10);

    % Define the z values as a function of x and y
    z = sin(sqrt(x.^2 + y.^2));

    % Create the mesh plot
    mesh(x, y, z);

    % Add labels and title
    xlabel('X-axis');
    ylabel('Y-axis');
    zlabel('Z-axis');
    title('Mesh Plot Example using meshgrid()');

    % Add a colorbar
    colorbar;
end

Prompt Example 2: Create MATLAB system class for Simulink block

# Create the following class for MATLAB system block
- Class name:add_noise
- Input: Vector signal
- Output: Vector signal
- Parameter: Level of noise
- Processing: Add white noise to the input signal

ChatGPT4-o Results

classdef add_noise < matlab.System
    % add_noise Add white noise to input signal
    %
    % This system object adds white noise to the input signal.

    properties
        % Level of noise
        NoiseLevel = 0.1; % Default noise level
    end

    methods (Access = protected)
        function setupImpl(obj)
            % Perform one-time calculations, such as computing constants
        end

        function y = stepImpl(obj, x)
            % Add white noise to the input signal
            %
            % x - input vector signal
            % y - output vector signal with added noise

            noise = obj.NoiseLevel * randn(size(x));
            y = x + noise;
        end

        function resetImpl(obj)
            % Initialize / reset discrete-state properties
        end

        function validateInputsImpl(obj, x)
            % Validate inputs to the step method at initialization
            validateattributes(x, {'numeric'}, {'vector'}, '', 'x');
        end

        function validatePropertiesImpl(obj)
            % Validate related or interdependent property values
            validateattributes(obj.NoiseLevel, {'numeric'}, {'scalar', 'nonnegative'}, '', 'NoiseLevel');
        end
    end

    methods (Access = protected)
        function processTunedPropertiesImpl(obj)
            % Handle changed properties that require an update to the system object
        end

        function releaseImpl(obj)
            % Release resources, such as file handles
        end
    end

    methods (Access = protected, Static)
        function header = getHeaderImpl
            % Define header panel for System block dialog
            header = matlab.system.display.Header(mfilename('class'));
        end

        function group = getPropertyGroupsImpl
            % Define property section(s) for System block dialog
            group = matlab.system.display.Section(...
                'PropertyList', {'NoiseLevel'});
        end
    end
end

引用格式

covao (2024). ClipAndTry (https://github.com/covao/ClipAndTry_MAT), GitHub. 检索时间: .

MATLAB 版本兼容性
创建方式 R2023a
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签

Community Treasure Hunt

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

Start Hunting!

无法下载基于 GitHub 默认分支的版本

版本 已发布 发行说明
1.0.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库