0

I'm new to MATLAB, so please pardon my naivety. There are many MATLAB CSV Read questions, but I believe this is different. I have a program that starts with

prompt = 'What is the name of the data vector to analyze? ';
data = input(prompt);

I respond with ’.../MATLAB Drive/File.csv’. But the compiler does not seem to respond with anything after being provided the file path:

Image of Non-Responsive Compiler

I'm not sure why this is the case. I tried doing data = csvread(filename) instead, as well as fopen('filename.csv'), as suggested by two of the answers above, but neither seemed to work. I also tried removing the three dots from the file path, as in MATLAB Drive/File.csv, but MATLAB then claims "Invalid use of operator", referring to the forward slash "/". If anyone has any advice for how to resolve this issue, that would be much appreciated.

On a perhaps related note, MATLAB seems to run an older version of my code even after I save and run -- I'm not sure if this is due to an error in the CSV or with the software.

rb3652
  • 425
  • 2
  • 12
  • 3
    `input` is not a csv file reading function. The syntax you used is not for inputting character or string arrays. Please read the documentation of [`input`](https://www.mathworks.com/help/matlab/ref/input.html) – Sardar Usama Oct 17 '22 at 09:41
  • 2
    Yes, we see that thetext input is colored, showing that it is interpreted as a code, not as a string (that would show the file location). Secondly, we see that active workspace is the Matlab Drive folder, but the input also defines the Matlab Drive folder. This is probably wrong, if the folder structure does not have two Matlab Drive folders one inside another. – VolkanOzcan Oct 17 '22 at 10:07
  • @SardarUsama Oh, I see. Thank you for the link to the docs, I see my mistake. Should I then use `csvread` or `fopen`? They didn't seem to work, although it could have been due to the second problem I noted. – rb3652 Oct 17 '22 at 10:07
  • @VolkanOzcan Does that mean my file path is wrong? I checked with `pwd` and I'm quite sure it's correct. – rb3652 Oct 17 '22 at 10:08
  • So your path already includes "Matlab Drive" folder right now, I can see it on the top side of the screen. Then, why do you still define the folder name in your input? Just the filename "EtEquiTest.csv" should be enough. When you write /Matlab Drive/ again it looks for another folder in that name, in your current path. – VolkanOzcan Oct 17 '22 at 10:09
  • @VolkanOzcan Ah, I see. Thank you for the tip. Let me try that. – rb3652 Oct 17 '22 at 10:10
  • As the @SardarUsama says, you still need to modify your import function as well. The input function just accepts some keyboard input from the user. It does not try to read any file. And by default it reads the input as code, so it runs it. You want the 's' parameter. Please check input documentation. – VolkanOzcan Oct 17 '22 at 10:12
  • @VolkanOzcan I see, thank you for all the help. And do you have any suggestions for the problem noted in the last paragraph? I'm not sure if it's related to my code or CSV, but MATLAB Online seems to run an old version of my code even when the new one is saved and ran? – rb3652 Oct 17 '22 at 10:13
  • That should not happen. you can try deleting all the old versions and making sure the new one is saved. You can also try the command "which functionname" to see how does the Matlab interpret the function or script name. – VolkanOzcan Oct 17 '22 at 10:15
  • 1
    "but MATLAB then claims "Invalid use of operator", referring to the forward slash "/"." These are all about the input function interpreting the input as code and trying to run it. Three dots suppress the error because three dots make the rest interpreted as a comment (green text). – VolkanOzcan Oct 17 '22 at 10:17

0 Answers0