Getting an error "Cannot call or index into a temporary array." (Code not written by me.)

This *.m file is a simple 2D line plot which I did not write. it repeatdly loads a series of Excel files and generates a *.png file of the plot. The error occurs in line 3, there are red sguiggles before both instances of "(1)". I have png files for many of the files, so I know the code worked at some point in time. As you can guess, I am a total newb at MATLAB! Code below:
file1 = dlmread("Results MSEEL 7557.xls");
Grey7557 = file1(:,3);
Depth7557 = linspace(7557,(7557+size(Grey7557)(1)*0.0016402),size(Grey7557)(1));
plot(Grey7557,Depth7557,'+')
axis("ij")
xlabel("Greyscale")
ylabel("Depth(ft)"), there are red sigules before
print -dpng Plot7557.png -S1200,1800;

回答 (1 件)

Star Strider
Star Strider 2020 年 9 月 11 日
If I understand the intent correctly, this should probably be:
Depth7557 = linspace(7557,(7557+size(Grey7557,1)*0.0016402),size(Grey7557,1));
such that:
size(Grey7557,1)
returns the row size of the Grey7557 vector. Since it appears to be a vector, numel would work as well, and could be more efficient.
.

4 件のコメント

@Star Strider, thanks for the quick reply.
I modified the code:
file1 = dlmread("Results MSEEL 7557.xls");
Grey7557 = file1(:,3);
Depth7557 = linspace(7557,(7557+size(Grey7557,1)*0.0016402),size(Grey7557,1));
plot(Grey7557,Depth7557,'+')
axis("ij")
xlabel("Greyscale")
ylabel("Depth(ft)"), there are red sigules before
print -dpng Plot7557_2.png -S1200,1800;
Now the code seems to have some other undesirable parts:
>> Read_Plot
Error: File: Read_Plot.m Line: 12 Column: 33
Indexing with parentheses '()' must appear as the last operation of a valid indexing expression.
>> Read_Plot_test
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> Area Mean StdDev Mode Min
Max Slice\n
Error in Read_Plot_test (line 1)
file1 = dlmread("Results MSEEL 7557.xls");
The plot should look like this:
Star Strider
Star Strider 2020 年 9 月 11 日
The dlmread function is not appropriate for a .xls file. Instead, use xlsread or in more recent MATLAB versions, readtable or readmatrix.
Walter Roberson
Walter Roberson 2020 年 9 月 11 日
It looks to me as if they are probably space or tab delimited files rather than actual xls files. dlmread() might be usable, if you specify R (row) as 1 .
Raymond McCleery
Raymond McCleery 2020 年 9 月 14 日
Thanks for the answers. The files say they are*.xls files but when I open them Excel gives a warning that the "file format and extension of <file name>.xls don't match. The file could be corrupted or unsafe...etc.", however they come up normally in Excel, so I assumed they were just and older version. Maybe they are not *.xls files.

サインインしてコメントする。

質問済み:

2020 年 9 月 11 日

コメント済み:

2020 年 9 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by