AI-Assisted Coding Guide — ECE Emerge

UC Davis — Spring 2026

Writing custom code to analyze real experimental data is a core engineering skill. This guide shows you how to do it efficiently and responsibly using AI tools. It applies to all labs requiring computational work.


1. The Ground Rule

You are responsible for every line of code you submit.

AI tools are powerful, but they make mistakes — sometimes subtle ones. In engineering, code you cannot explain is code you cannot trust. The goal is to use AI as a thinking partner, not as a shortcut that bypasses your own understanding.


2. Which Tool Should I Use?

You may use any programming language and any AI coding tool. MATLAB is the recommended default — all UC Davis students have access through the campus license, which includes MATLAB Copilot.

2. Which Tool Should I Use?
Your situation Recommended path
New to programming or unsure MATLAB + MATLAB Copilot
Comfortable with MATLAB MATLAB + any AI tool
Comfortable with Python Python + any AI tool
Want to try something new Pick either — both work

How to use MATLAB Copilot: Open MATLAB, then open the Copilot chat panel. Describe what you want in plain English and it will generate code you can paste directly into your script. You can ask follow-up questions in the same chat if something is unclear.


3. How to Write a Prompt That Works

The most common reason AI-generated code fails is a vague prompt. A good prompt has four parts:

Example Prompt

"I have two MATLAB vectors: t (time in seconds, length 500) and v (normalized voltage, values 0 to 1). Write MATLAB code that: (1) finds the index where v first drops below 0.368, (2) stores the corresponding time as tau, (3) plots v vs t with a horizontal dashed line at v = 0.368 and a vertical dashed line at t = tau, both labeled. After writing the code, explain what each section does in plain English."

Notice what makes this prompt effective: the data is described precisely, the output is specified clearly, and the AI is asked to explain its own code.


4. When the Code Does Not Work

  1. Paste the error back. Copy the full error message and line number and send it to the AI in the same conversation. Do not start a new chat — context matters.
  2. Check your data format. Most errors come from data import problems: wrong delimiter in a CSV, a row vector where a column vector is expected, or missing normalization.
  3. Ask the AI to debug step by step. Prompt: "Walk me through what this code does line by line and identify where the error might be coming from."
  4. If it fails three times, step back. Rewrite your prompt from scratch using the four-part structure in Section 3. A fresh, precise prompt often succeeds where a patched one keeps failing.

5. Verifying Your Output

Getting code to run without errors is not the same as getting the right answer. Always check:

When in doubt, check one data point by hand and compare it to what the code produces.


6. What to Submit

For any deliverable involving AI-assisted code, submit the following unless the lab document specifies otherwise:

6. What to Submit
Item
Complete, runnable code with a comment at the top naming the AI tool used (e.g., % Generated with MATLAB Copilot, adapted by [Your Name])
The plot or table produced by running that code on your data
A code review paragraph (3–5 sentences, your own words) explaining what the code does, one thing you verified or would change, and whether the output matches physical expectations

7. Academic Integrity

Using AI tools is encouraged. Submitting output you do not understand is not.

The code review paragraph in Section 6 is not busywork — it is how you demonstrate that you actually understand what was generated on your behalf. If you cannot write that paragraph, you are not ready to submit.