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.
| 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:
- What you have: Data names, units, size, and format.
- What you want: The output — a plot, a table, a calculated value.
- Any constraints: Language or specific functions to use or avoid.
- A verification request: Ask the AI to explain the code it just generated.
Example Prompt
"I have two MATLAB vectors:
t(time in seconds, length 500) andv(normalized voltage, values 0 to 1). Write MATLAB code that: (1) finds the index wherevfirst drops below 0.368, (2) stores the corresponding time astau, (3) plotsvvstwith a horizontal dashed line atv = 0.368and a vertical dashed line att = 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
- 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.
- 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.
- 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."
- 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:
- Does it make physical sense? Think about what your measurement represents. Is the magnitude reasonable? Does the trend match what you observed in the lab?
- Does the plot look right? Axes should be labeled with units. Values should fall in the range you expect. Threshold lines or markers should land where the physics says they should.
- Are your results consistent? If you process multiple trials or cycles, results should be similar across them. Large variation is a signal to investigate, not ignore.
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:
| 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.